blob: f115af101625013fc55a2431ac666b92c80c76f2 [file] [log] [blame]
Jim Laskey4bb9cbb2005-10-21 19:00:04 +00001//===- SubtargetEmitter.cpp - Generate subtarget enumerations -------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner30609102007-12-29 20:37:13 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Jim Laskey4bb9cbb2005-10-21 19:00:04 +00007//
8//===----------------------------------------------------------------------===//
9//
Chris Lattner3d878112006-03-03 02:04:07 +000010// This tablegen backend emits subtarget enumerations.
Jim Laskey4bb9cbb2005-10-21 19:00:04 +000011//
12//===----------------------------------------------------------------------===//
13
Andrew Trickfe05d982012-10-03 23:06:25 +000014#define DEBUG_TYPE "subtarget-emitter"
15
Jim Laskey4bb9cbb2005-10-21 19:00:04 +000016#include "CodeGenTarget.h"
Andrew Trick2661b412012-07-07 04:00:00 +000017#include "CodeGenSchedule.h"
Jim Laskey4bb9cbb2005-10-21 19:00:04 +000018#include "llvm/ADT/StringExtras.h"
Andrew Trick40096d22012-09-17 22:18:45 +000019#include "llvm/ADT/STLExtras.h"
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +000020#include "llvm/MC/MCInstrItineraries.h"
Andrew Trick40096d22012-09-17 22:18:45 +000021#include "llvm/TableGen/Error.h"
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +000022#include "llvm/TableGen/Record.h"
23#include "llvm/TableGen/TableGenBackend.h"
Andrew Trick40096d22012-09-17 22:18:45 +000024#include "llvm/Support/Debug.h"
Andrew Trick544c8802012-09-17 22:18:50 +000025#include "llvm/Support/Format.h"
Jeff Cohen9489c042005-10-28 01:43:09 +000026#include <algorithm>
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +000027#include <map>
28#include <string>
29#include <vector>
Jim Laskey4bb9cbb2005-10-21 19:00:04 +000030using namespace llvm;
31
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +000032namespace {
33class SubtargetEmitter {
Andrew Trick52c3a1d2012-09-17 22:18:48 +000034 // Each processor has a SchedClassDesc table with an entry for each SchedClass.
35 // The SchedClassDesc table indexes into a global write resource table, write
36 // latency table, and read advance table.
37 struct SchedClassTables {
38 std::vector<std::vector<MCSchedClassDesc> > ProcSchedClasses;
39 std::vector<MCWriteProcResEntry> WriteProcResources;
40 std::vector<MCWriteLatencyEntry> WriteLatencies;
Andrew Trick3b8fb642012-09-19 04:43:19 +000041 std::vector<std::string> WriterNames;
Andrew Trick52c3a1d2012-09-17 22:18:48 +000042 std::vector<MCReadAdvanceEntry> ReadAdvanceEntries;
43
44 // Reserve an invalid entry at index 0
45 SchedClassTables() {
46 ProcSchedClasses.resize(1);
47 WriteProcResources.resize(1);
48 WriteLatencies.resize(1);
Andrew Trick3b8fb642012-09-19 04:43:19 +000049 WriterNames.push_back("InvalidWrite");
Andrew Trick52c3a1d2012-09-17 22:18:48 +000050 ReadAdvanceEntries.resize(1);
51 }
52 };
53
54 struct LessWriteProcResources {
55 bool operator()(const MCWriteProcResEntry &LHS,
56 const MCWriteProcResEntry &RHS) {
57 return LHS.ProcResourceIdx < RHS.ProcResourceIdx;
58 }
59 };
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +000060
61 RecordKeeper &Records;
Andrew Trick2661b412012-07-07 04:00:00 +000062 CodeGenSchedModels &SchedModels;
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +000063 std::string Target;
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +000064
65 void Enumeration(raw_ostream &OS, const char *ClassName, bool isBits);
66 unsigned FeatureKeyValues(raw_ostream &OS);
67 unsigned CPUKeyValues(raw_ostream &OS);
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +000068 void FormItineraryStageString(const std::string &Names,
69 Record *ItinData, std::string &ItinString,
70 unsigned &NStages);
71 void FormItineraryOperandCycleString(Record *ItinData, std::string &ItinString,
72 unsigned &NOperandCycles);
73 void FormItineraryBypassString(const std::string &Names,
74 Record *ItinData,
75 std::string &ItinString, unsigned NOperandCycles);
Andrew Trick2661b412012-07-07 04:00:00 +000076 void EmitStageAndOperandCycleData(raw_ostream &OS,
77 std::vector<std::vector<InstrItinerary> >
78 &ProcItinLists);
79 void EmitItineraries(raw_ostream &OS,
80 std::vector<std::vector<InstrItinerary> >
81 &ProcItinLists);
82 void EmitProcessorProp(raw_ostream &OS, const Record *R, const char *Name,
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +000083 char Separator);
Andrew Trick40096d22012-09-17 22:18:45 +000084 void EmitProcessorResources(const CodeGenProcModel &ProcModel,
85 raw_ostream &OS);
Andrew Trick92649882012-09-22 02:24:21 +000086 Record *FindWriteResources(const CodeGenSchedRW &SchedWrite,
Andrew Trick52c3a1d2012-09-17 22:18:48 +000087 const CodeGenProcModel &ProcModel);
Andrew Trick92649882012-09-22 02:24:21 +000088 Record *FindReadAdvance(const CodeGenSchedRW &SchedRead,
89 const CodeGenProcModel &ProcModel);
Andrew Trick52c3a1d2012-09-17 22:18:48 +000090 void GenSchedClassTables(const CodeGenProcModel &ProcModel,
91 SchedClassTables &SchedTables);
Andrew Trick544c8802012-09-17 22:18:50 +000092 void EmitSchedClassTables(SchedClassTables &SchedTables, raw_ostream &OS);
Andrew Trick2661b412012-07-07 04:00:00 +000093 void EmitProcessorModels(raw_ostream &OS);
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +000094 void EmitProcessorLookup(raw_ostream &OS);
Andrew Trick4d2d1c42012-09-18 03:41:43 +000095 void EmitSchedModelHelpers(std::string ClassName, raw_ostream &OS);
Andrew Trick2661b412012-07-07 04:00:00 +000096 void EmitSchedModel(raw_ostream &OS);
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +000097 void ParseFeaturesFunction(raw_ostream &OS, unsigned NumFeatures,
98 unsigned NumProcs);
99
100public:
Andrew Trick2661b412012-07-07 04:00:00 +0000101 SubtargetEmitter(RecordKeeper &R, CodeGenTarget &TGT):
102 Records(R), SchedModels(TGT.getSchedModels()), Target(TGT.getName()) {}
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +0000103
104 void run(raw_ostream &o);
105
106};
107} // End anonymous namespace
108
Jim Laskey7dc02042005-10-22 07:59:56 +0000109//
Jim Laskey581a8f72005-10-26 17:30:34 +0000110// Enumeration - Emit the specified class as an enumeration.
Jim Laskeyb3b1d5f2005-10-25 15:16:36 +0000111//
Daniel Dunbar1a551802009-07-03 00:10:29 +0000112void SubtargetEmitter::Enumeration(raw_ostream &OS,
Jim Laskey581a8f72005-10-26 17:30:34 +0000113 const char *ClassName,
114 bool isBits) {
Jim Laskey908ae272005-10-28 15:20:43 +0000115 // Get all records of class and sort
Jim Laskeyf7bcde02005-10-28 21:47:29 +0000116 std::vector<Record*> DefList = Records.getAllDerivedDefinitions(ClassName);
Duraid Madina42d24c72005-12-30 14:56:37 +0000117 std::sort(DefList.begin(), DefList.end(), LessRecord());
Jim Laskeyb3b1d5f2005-10-25 15:16:36 +0000118
Evan Chengb6a63882011-04-15 19:35:46 +0000119 unsigned N = DefList.size();
Evan Cheng94214702011-07-01 20:45:01 +0000120 if (N == 0)
121 return;
Evan Chengb6a63882011-04-15 19:35:46 +0000122 if (N > 64) {
123 errs() << "Too many (> 64) subtarget features!\n";
124 exit(1);
125 }
126
Evan Cheng94214702011-07-01 20:45:01 +0000127 OS << "namespace " << Target << " {\n";
128
Jakob Stoklund Olesenac1ed442012-01-03 23:04:28 +0000129 // For bit flag enumerations with more than 32 items, emit constants.
130 // Emit an enum for everything else.
131 if (isBits && N > 32) {
132 // For each record
133 for (unsigned i = 0; i < N; i++) {
134 // Next record
135 Record *Def = DefList[i];
Evan Cheng94214702011-07-01 20:45:01 +0000136
Jakob Stoklund Olesenac1ed442012-01-03 23:04:28 +0000137 // Get and emit name and expression (1 << i)
138 OS << " const uint64_t " << Def->getName() << " = 1ULL << " << i << ";\n";
139 }
140 } else {
141 // Open enumeration
142 OS << "enum {\n";
Andrew Trickda96cf22011-04-01 01:56:55 +0000143
Jakob Stoklund Olesenac1ed442012-01-03 23:04:28 +0000144 // For each record
145 for (unsigned i = 0; i < N;) {
146 // Next record
147 Record *Def = DefList[i];
Andrew Trickda96cf22011-04-01 01:56:55 +0000148
Jakob Stoklund Olesenac1ed442012-01-03 23:04:28 +0000149 // Get and emit name
150 OS << " " << Def->getName();
Jim Laskey908ae272005-10-28 15:20:43 +0000151
Jakob Stoklund Olesenac1ed442012-01-03 23:04:28 +0000152 // If bit flags then emit expression (1 << i)
153 if (isBits) OS << " = " << " 1ULL << " << i;
Andrew Trickda96cf22011-04-01 01:56:55 +0000154
Jakob Stoklund Olesenac1ed442012-01-03 23:04:28 +0000155 // Depending on 'if more in the list' emit comma
156 if (++i < N) OS << ",";
157
158 OS << "\n";
159 }
160
161 // Close enumeration
162 OS << "};\n";
Jim Laskeyb3b1d5f2005-10-25 15:16:36 +0000163 }
Andrew Trickda96cf22011-04-01 01:56:55 +0000164
Evan Cheng94214702011-07-01 20:45:01 +0000165 OS << "}\n";
Jim Laskeyb3b1d5f2005-10-25 15:16:36 +0000166}
167
168//
Bill Wendling4222d802007-05-04 20:38:40 +0000169// FeatureKeyValues - Emit data of all the subtarget features. Used by the
170// command line.
Jim Laskeyb3b1d5f2005-10-25 15:16:36 +0000171//
Evan Cheng94214702011-07-01 20:45:01 +0000172unsigned SubtargetEmitter::FeatureKeyValues(raw_ostream &OS) {
Jim Laskey908ae272005-10-28 15:20:43 +0000173 // Gather and sort all the features
Jim Laskeyf7bcde02005-10-28 21:47:29 +0000174 std::vector<Record*> FeatureList =
175 Records.getAllDerivedDefinitions("SubtargetFeature");
Evan Cheng94214702011-07-01 20:45:01 +0000176
177 if (FeatureList.empty())
178 return 0;
179
Jim Grosbach7c9a7722008-09-11 17:05:32 +0000180 std::sort(FeatureList.begin(), FeatureList.end(), LessRecordFieldName());
Jim Laskeyb3b1d5f2005-10-25 15:16:36 +0000181
Jim Laskey908ae272005-10-28 15:20:43 +0000182 // Begin feature table
Jim Laskey581a8f72005-10-26 17:30:34 +0000183 OS << "// Sorted (by key) array of values for CPU features.\n"
Benjamin Kramer1a2f9882011-10-22 16:50:00 +0000184 << "extern const llvm::SubtargetFeatureKV " << Target
185 << "FeatureKV[] = {\n";
Andrew Trickda96cf22011-04-01 01:56:55 +0000186
Jim Laskey908ae272005-10-28 15:20:43 +0000187 // For each feature
Evan Cheng94214702011-07-01 20:45:01 +0000188 unsigned NumFeatures = 0;
Jim Laskeydbe40062006-12-12 20:55:58 +0000189 for (unsigned i = 0, N = FeatureList.size(); i < N; ++i) {
Jim Laskeyf7bcde02005-10-28 21:47:29 +0000190 // Next feature
191 Record *Feature = FeatureList[i];
192
Bill Wendling4222d802007-05-04 20:38:40 +0000193 const std::string &Name = Feature->getName();
194 const std::string &CommandLineName = Feature->getValueAsString("Name");
195 const std::string &Desc = Feature->getValueAsString("Desc");
Andrew Trickda96cf22011-04-01 01:56:55 +0000196
Jim Laskeydbe40062006-12-12 20:55:58 +0000197 if (CommandLineName.empty()) continue;
Andrew Trickda96cf22011-04-01 01:56:55 +0000198
Jim Grosbachda4231f2009-03-26 16:17:51 +0000199 // Emit as { "feature", "description", featureEnum, i1 | i2 | ... | in }
Jim Laskeyb3b1d5f2005-10-25 15:16:36 +0000200 OS << " { "
Jim Laskeyf7bcde02005-10-28 21:47:29 +0000201 << "\"" << CommandLineName << "\", "
Jim Laskeyb3b1d5f2005-10-25 15:16:36 +0000202 << "\"" << Desc << "\", "
Evan Cheng94214702011-07-01 20:45:01 +0000203 << Target << "::" << Name << ", ";
Bill Wendling4222d802007-05-04 20:38:40 +0000204
Andrew Trickda96cf22011-04-01 01:56:55 +0000205 const std::vector<Record*> &ImpliesList =
Bill Wendling4222d802007-05-04 20:38:40 +0000206 Feature->getValueAsListOfDefs("Implies");
Andrew Trickda96cf22011-04-01 01:56:55 +0000207
Bill Wendling4222d802007-05-04 20:38:40 +0000208 if (ImpliesList.empty()) {
Evan Chengb6a63882011-04-15 19:35:46 +0000209 OS << "0ULL";
Bill Wendling4222d802007-05-04 20:38:40 +0000210 } else {
211 for (unsigned j = 0, M = ImpliesList.size(); j < M;) {
Evan Cheng94214702011-07-01 20:45:01 +0000212 OS << Target << "::" << ImpliesList[j]->getName();
Bill Wendling4222d802007-05-04 20:38:40 +0000213 if (++j < M) OS << " | ";
214 }
215 }
216
217 OS << " }";
Evan Cheng94214702011-07-01 20:45:01 +0000218 ++NumFeatures;
Andrew Trickda96cf22011-04-01 01:56:55 +0000219
Jim Laskey10b1dd92005-10-31 17:16:01 +0000220 // Depending on 'if more in the list' emit comma
Jim Laskeydbe40062006-12-12 20:55:58 +0000221 if ((i + 1) < N) OS << ",";
Andrew Trickda96cf22011-04-01 01:56:55 +0000222
Jim Laskeyf7bcde02005-10-28 21:47:29 +0000223 OS << "\n";
Jim Laskeyb3b1d5f2005-10-25 15:16:36 +0000224 }
Andrew Trickda96cf22011-04-01 01:56:55 +0000225
Jim Laskey908ae272005-10-28 15:20:43 +0000226 // End feature table
Jim Laskeyb3b1d5f2005-10-25 15:16:36 +0000227 OS << "};\n";
228
Evan Cheng94214702011-07-01 20:45:01 +0000229 return NumFeatures;
Jim Laskeyb3b1d5f2005-10-25 15:16:36 +0000230}
231
232//
233// CPUKeyValues - Emit data of all the subtarget processors. Used by command
234// line.
235//
Evan Cheng94214702011-07-01 20:45:01 +0000236unsigned SubtargetEmitter::CPUKeyValues(raw_ostream &OS) {
Jim Laskey908ae272005-10-28 15:20:43 +0000237 // Gather and sort processor information
Jim Laskeyf7bcde02005-10-28 21:47:29 +0000238 std::vector<Record*> ProcessorList =
239 Records.getAllDerivedDefinitions("Processor");
Duraid Madina42d24c72005-12-30 14:56:37 +0000240 std::sort(ProcessorList.begin(), ProcessorList.end(), LessRecordFieldName());
Jim Laskeyb3b1d5f2005-10-25 15:16:36 +0000241
Jim Laskey908ae272005-10-28 15:20:43 +0000242 // Begin processor table
Jim Laskey581a8f72005-10-26 17:30:34 +0000243 OS << "// Sorted (by key) array of values for CPU subtype.\n"
Benjamin Kramer1a2f9882011-10-22 16:50:00 +0000244 << "extern const llvm::SubtargetFeatureKV " << Target
245 << "SubTypeKV[] = {\n";
Andrew Trickda96cf22011-04-01 01:56:55 +0000246
Jim Laskey908ae272005-10-28 15:20:43 +0000247 // For each processor
Jim Laskeyf7bcde02005-10-28 21:47:29 +0000248 for (unsigned i = 0, N = ProcessorList.size(); i < N;) {
249 // Next processor
250 Record *Processor = ProcessorList[i];
251
Bill Wendling4222d802007-05-04 20:38:40 +0000252 const std::string &Name = Processor->getValueAsString("Name");
Andrew Trickda96cf22011-04-01 01:56:55 +0000253 const std::vector<Record*> &FeatureList =
Chris Lattnerb0e103d2005-10-28 22:49:02 +0000254 Processor->getValueAsListOfDefs("Features");
Andrew Trickda96cf22011-04-01 01:56:55 +0000255
Jim Laskey908ae272005-10-28 15:20:43 +0000256 // Emit as { "cpu", "description", f1 | f2 | ... fn },
Jim Laskeyb3b1d5f2005-10-25 15:16:36 +0000257 OS << " { "
258 << "\"" << Name << "\", "
259 << "\"Select the " << Name << " processor\", ";
Andrew Trickda96cf22011-04-01 01:56:55 +0000260
Jim Laskeyf7bcde02005-10-28 21:47:29 +0000261 if (FeatureList.empty()) {
Evan Chengb6a63882011-04-15 19:35:46 +0000262 OS << "0ULL";
Jim Laskeyb3b1d5f2005-10-25 15:16:36 +0000263 } else {
Jim Laskeyf7bcde02005-10-28 21:47:29 +0000264 for (unsigned j = 0, M = FeatureList.size(); j < M;) {
Evan Cheng94214702011-07-01 20:45:01 +0000265 OS << Target << "::" << FeatureList[j]->getName();
Jim Laskeyf7bcde02005-10-28 21:47:29 +0000266 if (++j < M) OS << " | ";
Jim Laskeyb3b1d5f2005-10-25 15:16:36 +0000267 }
268 }
Andrew Trickda96cf22011-04-01 01:56:55 +0000269
Bill Wendling4222d802007-05-04 20:38:40 +0000270 // The "0" is for the "implies" section of this data structure.
Evan Chengb6a63882011-04-15 19:35:46 +0000271 OS << ", 0ULL }";
Andrew Trickda96cf22011-04-01 01:56:55 +0000272
Jim Laskey10b1dd92005-10-31 17:16:01 +0000273 // Depending on 'if more in the list' emit comma
Jim Laskeyf7bcde02005-10-28 21:47:29 +0000274 if (++i < N) OS << ",";
Andrew Trickda96cf22011-04-01 01:56:55 +0000275
Jim Laskeyf7bcde02005-10-28 21:47:29 +0000276 OS << "\n";
Jim Laskeyb3b1d5f2005-10-25 15:16:36 +0000277 }
Andrew Trickda96cf22011-04-01 01:56:55 +0000278
Jim Laskey908ae272005-10-28 15:20:43 +0000279 // End processor table
Jim Laskeyb3b1d5f2005-10-25 15:16:36 +0000280 OS << "};\n";
281
Evan Cheng94214702011-07-01 20:45:01 +0000282 return ProcessorList.size();
Jim Laskeyb3b1d5f2005-10-25 15:16:36 +0000283}
Jim Laskey7dc02042005-10-22 07:59:56 +0000284
Jim Laskey581a8f72005-10-26 17:30:34 +0000285//
David Goodwinfac85412009-08-17 16:02:57 +0000286// FormItineraryStageString - Compose a string containing the stage
287// data initialization for the specified itinerary. N is the number
288// of stages.
Jim Laskey0d841e02005-10-27 19:47:21 +0000289//
Anton Korobeynikov928eb492010-04-18 20:31:01 +0000290void SubtargetEmitter::FormItineraryStageString(const std::string &Name,
291 Record *ItinData,
David Goodwinfac85412009-08-17 16:02:57 +0000292 std::string &ItinString,
293 unsigned &NStages) {
Jim Laskeyf7bcde02005-10-28 21:47:29 +0000294 // Get states list
Bill Wendling4222d802007-05-04 20:38:40 +0000295 const std::vector<Record*> &StageList =
296 ItinData->getValueAsListOfDefs("Stages");
Jim Laskey908ae272005-10-28 15:20:43 +0000297
298 // For each stage
Jim Laskeyf7bcde02005-10-28 21:47:29 +0000299 unsigned N = NStages = StageList.size();
Christopher Lamb8dadf6b2007-04-22 09:04:24 +0000300 for (unsigned i = 0; i < N;) {
Jim Laskeyf7bcde02005-10-28 21:47:29 +0000301 // Next stage
Bill Wendling4222d802007-05-04 20:38:40 +0000302 const Record *Stage = StageList[i];
Andrew Trickda96cf22011-04-01 01:56:55 +0000303
Anton Korobeynikov96085a32010-04-07 18:19:32 +0000304 // Form string as ,{ cycles, u1 | u2 | ... | un, timeinc, kind }
Jim Laskey0d841e02005-10-27 19:47:21 +0000305 int Cycles = Stage->getValueAsInt("Cycles");
Jim Laskey7f39c142005-11-03 22:47:41 +0000306 ItinString += " { " + itostr(Cycles) + ", ";
Andrew Trickda96cf22011-04-01 01:56:55 +0000307
Jim Laskeyf7bcde02005-10-28 21:47:29 +0000308 // Get unit list
Bill Wendling4222d802007-05-04 20:38:40 +0000309 const std::vector<Record*> &UnitList = Stage->getValueAsListOfDefs("Units");
Andrew Trickda96cf22011-04-01 01:56:55 +0000310
Jim Laskey908ae272005-10-28 15:20:43 +0000311 // For each unit
Jim Laskeyf7bcde02005-10-28 21:47:29 +0000312 for (unsigned j = 0, M = UnitList.size(); j < M;) {
Jim Laskeyf7bcde02005-10-28 21:47:29 +0000313 // Add name and bitwise or
Anton Korobeynikov928eb492010-04-18 20:31:01 +0000314 ItinString += Name + "FU::" + UnitList[j]->getName();
Jim Laskeyf7bcde02005-10-28 21:47:29 +0000315 if (++j < M) ItinString += " | ";
Jim Laskey0d841e02005-10-27 19:47:21 +0000316 }
Andrew Trickda96cf22011-04-01 01:56:55 +0000317
David Goodwin1a8f36e2009-08-12 18:31:53 +0000318 int TimeInc = Stage->getValueAsInt("TimeInc");
319 ItinString += ", " + itostr(TimeInc);
320
Anton Korobeynikov96085a32010-04-07 18:19:32 +0000321 int Kind = Stage->getValueAsInt("Kind");
322 ItinString += ", (llvm::InstrStage::ReservationKinds)" + itostr(Kind);
323
Jim Laskey908ae272005-10-28 15:20:43 +0000324 // Close off stage
325 ItinString += " }";
Christopher Lamb8dadf6b2007-04-22 09:04:24 +0000326 if (++i < N) ItinString += ", ";
Jim Laskey0d841e02005-10-27 19:47:21 +0000327 }
Jim Laskey0d841e02005-10-27 19:47:21 +0000328}
329
330//
David Goodwinfac85412009-08-17 16:02:57 +0000331// FormItineraryOperandCycleString - Compose a string containing the
332// operand cycle initialization for the specified itinerary. N is the
333// number of operands that has cycles specified.
Jim Laskey0d841e02005-10-27 19:47:21 +0000334//
David Goodwinfac85412009-08-17 16:02:57 +0000335void SubtargetEmitter::FormItineraryOperandCycleString(Record *ItinData,
336 std::string &ItinString, unsigned &NOperandCycles) {
337 // Get operand cycle list
338 const std::vector<int64_t> &OperandCycleList =
339 ItinData->getValueAsListOfInts("OperandCycles");
340
341 // For each operand cycle
342 unsigned N = NOperandCycles = OperandCycleList.size();
343 for (unsigned i = 0; i < N;) {
344 // Next operand cycle
345 const int OCycle = OperandCycleList[i];
Andrew Trickda96cf22011-04-01 01:56:55 +0000346
David Goodwinfac85412009-08-17 16:02:57 +0000347 ItinString += " " + itostr(OCycle);
348 if (++i < N) ItinString += ", ";
349 }
350}
351
Evan Cheng63d66ee2010-09-28 23:50:49 +0000352void SubtargetEmitter::FormItineraryBypassString(const std::string &Name,
353 Record *ItinData,
354 std::string &ItinString,
355 unsigned NOperandCycles) {
356 const std::vector<Record*> &BypassList =
357 ItinData->getValueAsListOfDefs("Bypasses");
358 unsigned N = BypassList.size();
Evan Cheng3881cb72010-09-29 22:42:35 +0000359 unsigned i = 0;
360 for (; i < N;) {
Evan Cheng63d66ee2010-09-28 23:50:49 +0000361 ItinString += Name + "Bypass::" + BypassList[i]->getName();
Evan Cheng3881cb72010-09-29 22:42:35 +0000362 if (++i < NOperandCycles) ItinString += ", ";
Evan Cheng63d66ee2010-09-28 23:50:49 +0000363 }
Evan Cheng3881cb72010-09-29 22:42:35 +0000364 for (; i < NOperandCycles;) {
Evan Cheng63d66ee2010-09-28 23:50:49 +0000365 ItinString += " 0";
Evan Cheng3881cb72010-09-29 22:42:35 +0000366 if (++i < NOperandCycles) ItinString += ", ";
Evan Cheng63d66ee2010-09-28 23:50:49 +0000367 }
368}
369
David Goodwinfac85412009-08-17 16:02:57 +0000370//
Andrew Trick2661b412012-07-07 04:00:00 +0000371// EmitStageAndOperandCycleData - Generate unique itinerary stages and operand
372// cycle tables. Create a list of InstrItinerary objects (ProcItinLists) indexed
373// by CodeGenSchedClass::Index.
David Goodwinfac85412009-08-17 16:02:57 +0000374//
Andrew Trick2661b412012-07-07 04:00:00 +0000375void SubtargetEmitter::
376EmitStageAndOperandCycleData(raw_ostream &OS,
377 std::vector<std::vector<InstrItinerary> >
378 &ProcItinLists) {
Jim Laskey908ae272005-10-28 15:20:43 +0000379
Andrew Trickcb941922012-07-09 20:43:03 +0000380 // Multiple processor models may share an itinerary record. Emit it once.
381 SmallPtrSet<Record*, 8> ItinsDefSet;
382
Anton Korobeynikov928eb492010-04-18 20:31:01 +0000383 // Emit functional units for all the itineraries.
Andrew Trick2661b412012-07-07 04:00:00 +0000384 for (CodeGenSchedModels::ProcIter PI = SchedModels.procModelBegin(),
385 PE = SchedModels.procModelEnd(); PI != PE; ++PI) {
Anton Korobeynikov928eb492010-04-18 20:31:01 +0000386
Andrew Trickcb941922012-07-09 20:43:03 +0000387 if (!ItinsDefSet.insert(PI->ItinsDef))
388 continue;
389
Andrew Trick2661b412012-07-07 04:00:00 +0000390 std::vector<Record*> FUs = PI->ItinsDef->getValueAsListOfDefs("FU");
Anton Korobeynikov928eb492010-04-18 20:31:01 +0000391 if (FUs.empty())
392 continue;
393
Andrew Trick2661b412012-07-07 04:00:00 +0000394 const std::string &Name = PI->ItinsDef->getName();
395 OS << "\n// Functional units for \"" << Name << "\"\n"
Anton Korobeynikov928eb492010-04-18 20:31:01 +0000396 << "namespace " << Name << "FU {\n";
397
398 for (unsigned j = 0, FUN = FUs.size(); j < FUN; ++j)
Hal Finkelb460a332012-06-22 20:27:13 +0000399 OS << " const unsigned " << FUs[j]->getName()
400 << " = 1 << " << j << ";\n";
Anton Korobeynikov928eb492010-04-18 20:31:01 +0000401
402 OS << "}\n";
Evan Cheng63d66ee2010-09-28 23:50:49 +0000403
Andrew Trick2661b412012-07-07 04:00:00 +0000404 std::vector<Record*> BPs = PI->ItinsDef->getValueAsListOfDefs("BP");
Evan Cheng3881cb72010-09-29 22:42:35 +0000405 if (BPs.size()) {
406 OS << "\n// Pipeline forwarding pathes for itineraries \"" << Name
407 << "\"\n" << "namespace " << Name << "Bypass {\n";
Evan Cheng63d66ee2010-09-28 23:50:49 +0000408
Benjamin Kramer1a2f9882011-10-22 16:50:00 +0000409 OS << " const unsigned NoBypass = 0;\n";
Evan Cheng3881cb72010-09-29 22:42:35 +0000410 for (unsigned j = 0, BPN = BPs.size(); j < BPN; ++j)
Benjamin Kramer1a2f9882011-10-22 16:50:00 +0000411 OS << " const unsigned " << BPs[j]->getName()
Evan Cheng3881cb72010-09-29 22:42:35 +0000412 << " = 1 << " << j << ";\n";
Evan Cheng63d66ee2010-09-28 23:50:49 +0000413
Evan Cheng3881cb72010-09-29 22:42:35 +0000414 OS << "}\n";
415 }
Anton Korobeynikov928eb492010-04-18 20:31:01 +0000416 }
417
Jim Laskey908ae272005-10-28 15:20:43 +0000418 // Begin stages table
Benjamin Kramer1a2f9882011-10-22 16:50:00 +0000419 std::string StageTable = "\nextern const llvm::InstrStage " + Target +
420 "Stages[] = {\n";
Anton Korobeynikov96085a32010-04-07 18:19:32 +0000421 StageTable += " { 0, 0, 0, llvm::InstrStage::Required }, // No itinerary\n";
Andrew Trickda96cf22011-04-01 01:56:55 +0000422
David Goodwinfac85412009-08-17 16:02:57 +0000423 // Begin operand cycle table
Benjamin Kramer1a2f9882011-10-22 16:50:00 +0000424 std::string OperandCycleTable = "extern const unsigned " + Target +
Evan Cheng94214702011-07-01 20:45:01 +0000425 "OperandCycles[] = {\n";
David Goodwinfac85412009-08-17 16:02:57 +0000426 OperandCycleTable += " 0, // No itinerary\n";
Evan Cheng63d66ee2010-09-28 23:50:49 +0000427
428 // Begin pipeline bypass table
Benjamin Kramer1a2f9882011-10-22 16:50:00 +0000429 std::string BypassTable = "extern const unsigned " + Target +
Andrew Tricka11a6282012-07-07 03:59:48 +0000430 "ForwardingPaths[] = {\n";
Andrew Trick2661b412012-07-07 04:00:00 +0000431 BypassTable += " 0, // No itinerary\n";
Andrew Trickda96cf22011-04-01 01:56:55 +0000432
Andrew Trick2661b412012-07-07 04:00:00 +0000433 // For each Itinerary across all processors, add a unique entry to the stages,
434 // operand cycles, and pipepine bypess tables. Then add the new Itinerary
435 // object with computed offsets to the ProcItinLists result.
David Goodwinfac85412009-08-17 16:02:57 +0000436 unsigned StageCount = 1, OperandCycleCount = 1;
Evan Cheng3881cb72010-09-29 22:42:35 +0000437 std::map<std::string, unsigned> ItinStageMap, ItinOperandMap;
Andrew Trick2661b412012-07-07 04:00:00 +0000438 for (CodeGenSchedModels::ProcIter PI = SchedModels.procModelBegin(),
439 PE = SchedModels.procModelEnd(); PI != PE; ++PI) {
440 const CodeGenProcModel &ProcModel = *PI;
Andrew Trickda96cf22011-04-01 01:56:55 +0000441
Andrew Trick2661b412012-07-07 04:00:00 +0000442 // Add process itinerary to the list.
443 ProcItinLists.resize(ProcItinLists.size()+1);
Andrew Trickda96cf22011-04-01 01:56:55 +0000444
Andrew Trick2661b412012-07-07 04:00:00 +0000445 // If this processor defines no itineraries, then leave the itinerary list
446 // empty.
447 std::vector<InstrItinerary> &ItinList = ProcItinLists.back();
448 if (ProcModel.ItinDefList.empty())
Andrew Trickd85934b2012-06-22 03:58:51 +0000449 continue;
Andrew Trickd85934b2012-06-22 03:58:51 +0000450
Andrew Trick2661b412012-07-07 04:00:00 +0000451 // Reserve index==0 for NoItinerary.
452 ItinList.resize(SchedModels.numItineraryClasses()+1);
453
454 const std::string &Name = ProcModel.ItinsDef->getName();
Andrew Trickda96cf22011-04-01 01:56:55 +0000455
Jim Laskeyf7bcde02005-10-28 21:47:29 +0000456 // For each itinerary data
Andrew Trick2661b412012-07-07 04:00:00 +0000457 for (unsigned SchedClassIdx = 0,
458 SchedClassEnd = ProcModel.ItinDefList.size();
459 SchedClassIdx < SchedClassEnd; ++SchedClassIdx) {
460
Jim Laskeyf7bcde02005-10-28 21:47:29 +0000461 // Next itinerary data
Andrew Trick2661b412012-07-07 04:00:00 +0000462 Record *ItinData = ProcModel.ItinDefList[SchedClassIdx];
Andrew Trickda96cf22011-04-01 01:56:55 +0000463
Jim Laskey908ae272005-10-28 15:20:43 +0000464 // Get string and stage count
David Goodwinfac85412009-08-17 16:02:57 +0000465 std::string ItinStageString;
Andrew Trick2661b412012-07-07 04:00:00 +0000466 unsigned NStages = 0;
467 if (ItinData)
468 FormItineraryStageString(Name, ItinData, ItinStageString, NStages);
Jim Laskey0d841e02005-10-27 19:47:21 +0000469
David Goodwinfac85412009-08-17 16:02:57 +0000470 // Get string and operand cycle count
471 std::string ItinOperandCycleString;
Andrew Trick2661b412012-07-07 04:00:00 +0000472 unsigned NOperandCycles = 0;
Evan Cheng63d66ee2010-09-28 23:50:49 +0000473 std::string ItinBypassString;
Andrew Trick2661b412012-07-07 04:00:00 +0000474 if (ItinData) {
475 FormItineraryOperandCycleString(ItinData, ItinOperandCycleString,
476 NOperandCycles);
477
478 FormItineraryBypassString(Name, ItinData, ItinBypassString,
479 NOperandCycles);
480 }
Evan Cheng63d66ee2010-09-28 23:50:49 +0000481
David Goodwinfac85412009-08-17 16:02:57 +0000482 // Check to see if stage already exists and create if it doesn't
483 unsigned FindStage = 0;
484 if (NStages > 0) {
485 FindStage = ItinStageMap[ItinStageString];
486 if (FindStage == 0) {
Andrew Trick23482322011-04-01 02:22:47 +0000487 // Emit as { cycles, u1 | u2 | ... | un, timeinc }, // indices
488 StageTable += ItinStageString + ", // " + itostr(StageCount);
489 if (NStages > 1)
490 StageTable += "-" + itostr(StageCount + NStages - 1);
491 StageTable += "\n";
David Goodwinfac85412009-08-17 16:02:57 +0000492 // Record Itin class number.
493 ItinStageMap[ItinStageString] = FindStage = StageCount;
494 StageCount += NStages;
David Goodwinfac85412009-08-17 16:02:57 +0000495 }
496 }
Andrew Trickda96cf22011-04-01 01:56:55 +0000497
David Goodwinfac85412009-08-17 16:02:57 +0000498 // Check to see if operand cycle already exists and create if it doesn't
499 unsigned FindOperandCycle = 0;
500 if (NOperandCycles > 0) {
Evan Cheng3881cb72010-09-29 22:42:35 +0000501 std::string ItinOperandString = ItinOperandCycleString+ItinBypassString;
502 FindOperandCycle = ItinOperandMap[ItinOperandString];
David Goodwinfac85412009-08-17 16:02:57 +0000503 if (FindOperandCycle == 0) {
504 // Emit as cycle, // index
Andrew Trick23482322011-04-01 02:22:47 +0000505 OperandCycleTable += ItinOperandCycleString + ", // ";
506 std::string OperandIdxComment = itostr(OperandCycleCount);
507 if (NOperandCycles > 1)
508 OperandIdxComment += "-"
509 + itostr(OperandCycleCount + NOperandCycles - 1);
510 OperandCycleTable += OperandIdxComment + "\n";
David Goodwinfac85412009-08-17 16:02:57 +0000511 // Record Itin class number.
Andrew Trickda96cf22011-04-01 01:56:55 +0000512 ItinOperandMap[ItinOperandCycleString] =
David Goodwinfac85412009-08-17 16:02:57 +0000513 FindOperandCycle = OperandCycleCount;
Evan Cheng63d66ee2010-09-28 23:50:49 +0000514 // Emit as bypass, // index
Andrew Trick23482322011-04-01 02:22:47 +0000515 BypassTable += ItinBypassString + ", // " + OperandIdxComment + "\n";
David Goodwinfac85412009-08-17 16:02:57 +0000516 OperandCycleCount += NOperandCycles;
David Goodwinfac85412009-08-17 16:02:57 +0000517 }
Jim Laskey0d841e02005-10-27 19:47:21 +0000518 }
Andrew Trickda96cf22011-04-01 01:56:55 +0000519
Evan Cheng5f54ce32010-09-09 18:18:55 +0000520 // Set up itinerary as location and location + stage count
Andrew Trick2661b412012-07-07 04:00:00 +0000521 int NumUOps = ItinData ? ItinData->getValueAsInt("NumMicroOps") : 0;
Evan Cheng5f54ce32010-09-09 18:18:55 +0000522 InstrItinerary Intinerary = { NumUOps, FindStage, FindStage + NStages,
523 FindOperandCycle,
524 FindOperandCycle + NOperandCycles};
525
Jim Laskey908ae272005-10-28 15:20:43 +0000526 // Inject - empty slots will be 0, 0
Andrew Trick2661b412012-07-07 04:00:00 +0000527 ItinList[SchedClassIdx] = Intinerary;
Jim Laskey0d841e02005-10-27 19:47:21 +0000528 }
Jim Laskey0d841e02005-10-27 19:47:21 +0000529 }
Evan Cheng63d66ee2010-09-28 23:50:49 +0000530
Jim Laskey7f39c142005-11-03 22:47:41 +0000531 // Closing stage
Andrew Trick2661b412012-07-07 04:00:00 +0000532 StageTable += " { 0, 0, 0, llvm::InstrStage::Required } // End stages\n";
David Goodwinfac85412009-08-17 16:02:57 +0000533 StageTable += "};\n";
534
535 // Closing operand cycles
Andrew Trick2661b412012-07-07 04:00:00 +0000536 OperandCycleTable += " 0 // End operand cycles\n";
David Goodwinfac85412009-08-17 16:02:57 +0000537 OperandCycleTable += "};\n";
538
Andrew Trick2661b412012-07-07 04:00:00 +0000539 BypassTable += " 0 // End bypass tables\n";
Evan Cheng63d66ee2010-09-28 23:50:49 +0000540 BypassTable += "};\n";
541
David Goodwinfac85412009-08-17 16:02:57 +0000542 // Emit tables.
543 OS << StageTable;
544 OS << OperandCycleTable;
Evan Cheng63d66ee2010-09-28 23:50:49 +0000545 OS << BypassTable;
Jim Laskey0d841e02005-10-27 19:47:21 +0000546}
547
Andrew Trick2661b412012-07-07 04:00:00 +0000548//
549// EmitProcessorData - Generate data for processor itineraries that were
550// computed during EmitStageAndOperandCycleData(). ProcItinLists lists all
551// Itineraries for each processor. The Itinerary lists are indexed on
552// CodeGenSchedClass::Index.
553//
554void SubtargetEmitter::
555EmitItineraries(raw_ostream &OS,
556 std::vector<std::vector<InstrItinerary> > &ProcItinLists) {
557
Andrew Trickcb941922012-07-09 20:43:03 +0000558 // Multiple processor models may share an itinerary record. Emit it once.
559 SmallPtrSet<Record*, 8> ItinsDefSet;
560
Andrew Trick2661b412012-07-07 04:00:00 +0000561 // For each processor's machine model
562 std::vector<std::vector<InstrItinerary> >::iterator
563 ProcItinListsIter = ProcItinLists.begin();
564 for (CodeGenSchedModels::ProcIter PI = SchedModels.procModelBegin(),
Andrew Trick48605c32012-09-15 00:19:57 +0000565 PE = SchedModels.procModelEnd(); PI != PE; ++PI, ++ProcItinListsIter) {
Andrew Trickcb941922012-07-09 20:43:03 +0000566
Andrew Trick2661b412012-07-07 04:00:00 +0000567 Record *ItinsDef = PI->ItinsDef;
Andrew Trickcb941922012-07-09 20:43:03 +0000568 if (!ItinsDefSet.insert(ItinsDef))
569 continue;
Andrew Trick2661b412012-07-07 04:00:00 +0000570
571 // Get processor itinerary name
572 const std::string &Name = ItinsDef->getName();
573
574 // Get the itinerary list for the processor.
575 assert(ProcItinListsIter != ProcItinLists.end() && "bad iterator");
Andrew Trick48605c32012-09-15 00:19:57 +0000576 std::vector<InstrItinerary> &ItinList = *ProcItinListsIter;
Andrew Trick2661b412012-07-07 04:00:00 +0000577
578 OS << "\n";
579 OS << "static const llvm::InstrItinerary ";
580 if (ItinList.empty()) {
581 OS << '*' << Name << " = 0;\n";
582 continue;
583 }
584
585 // Begin processor itinerary table
586 OS << Name << "[] = {\n";
587
588 // For each itinerary class in CodeGenSchedClass::Index order.
589 for (unsigned j = 0, M = ItinList.size(); j < M; ++j) {
590 InstrItinerary &Intinerary = ItinList[j];
591
592 // Emit Itinerary in the form of
593 // { firstStage, lastStage, firstCycle, lastCycle } // index
594 OS << " { " <<
595 Intinerary.NumMicroOps << ", " <<
596 Intinerary.FirstStage << ", " <<
597 Intinerary.LastStage << ", " <<
598 Intinerary.FirstOperandCycle << ", " <<
599 Intinerary.LastOperandCycle << " }" <<
600 ", // " << j << " " << SchedModels.getSchedClass(j).Name << "\n";
601 }
602 // End processor itinerary table
603 OS << " { 0, ~0U, ~0U, ~0U, ~0U } // end marker\n";
604 OS << "};\n";
605 }
606}
607
Sylvestre Ledruc8e41c52012-07-23 08:51:15 +0000608// Emit either the value defined in the TableGen Record, or the default
Andrew Trick2661b412012-07-07 04:00:00 +0000609// value defined in the C++ header. The Record is null if the processor does not
610// define a model.
611void SubtargetEmitter::EmitProcessorProp(raw_ostream &OS, const Record *R,
Andrew Trickfc992992012-06-05 03:44:40 +0000612 const char *Name, char Separator) {
613 OS << " ";
Andrew Trick2661b412012-07-07 04:00:00 +0000614 int V = R ? R->getValueAsInt(Name) : -1;
Andrew Trickfc992992012-06-05 03:44:40 +0000615 if (V >= 0)
616 OS << V << Separator << " // " << Name;
617 else
Andrew Trick2661b412012-07-07 04:00:00 +0000618 OS << "MCSchedModel::Default" << Name << Separator;
Andrew Trickfc992992012-06-05 03:44:40 +0000619 OS << '\n';
620}
621
Andrew Trick40096d22012-09-17 22:18:45 +0000622void SubtargetEmitter::EmitProcessorResources(const CodeGenProcModel &ProcModel,
623 raw_ostream &OS) {
624 char Sep = ProcModel.ProcResourceDefs.empty() ? ' ' : ',';
625
626 OS << "\n// {Name, NumUnits, SuperIdx}\n";
627 OS << "static const llvm::MCProcResourceDesc "
628 << ProcModel.ModelName << "ProcResources" << "[] = {\n"
629 << " {DBGFIELD(\"InvalidUnit\") 0, 0}" << Sep << "\n";
630
631 for (unsigned i = 0, e = ProcModel.ProcResourceDefs.size(); i < e; ++i) {
632 Record *PRDef = ProcModel.ProcResourceDefs[i];
633
634 // Find the SuperIdx
635 unsigned SuperIdx = 0;
636 Record *SuperDef = 0;
637 if (PRDef->getValueInit("Super")->isComplete()) {
638 SuperDef =
639 SchedModels.findProcResUnits(PRDef->getValueAsDef("Super"), ProcModel);
640 SuperIdx = ProcModel.getProcResourceIdx(SuperDef);
641 }
642 // Emit the ProcResourceDesc
643 if (i+1 == e)
644 Sep = ' ';
645 OS << " {DBGFIELD(\"" << PRDef->getName() << "\") ";
646 if (PRDef->getName().size() < 15)
647 OS.indent(15 - PRDef->getName().size());
648 OS << PRDef->getValueAsInt("NumUnits") << ", " << SuperIdx
649 << "}" << Sep << " // #" << i+1;
650 if (SuperDef)
651 OS << ", Super=" << SuperDef->getName();
652 OS << "\n";
653 }
654 OS << "};\n";
655}
656
Andrew Trick52c3a1d2012-09-17 22:18:48 +0000657// Find the WriteRes Record that defines processor resources for this
658// SchedWrite.
659Record *SubtargetEmitter::FindWriteResources(
Andrew Trick92649882012-09-22 02:24:21 +0000660 const CodeGenSchedRW &SchedWrite, const CodeGenProcModel &ProcModel) {
Andrew Trick52c3a1d2012-09-17 22:18:48 +0000661
662 // Check if the SchedWrite is already subtarget-specific and directly
663 // specifies a set of processor resources.
Andrew Trick92649882012-09-22 02:24:21 +0000664 if (SchedWrite.TheDef->isSubClassOf("SchedWriteRes"))
665 return SchedWrite.TheDef;
666
667 // Check this processor's list of aliases for SchedWrite.
668 Record *AliasDef = 0;
669 for (RecIter AI = SchedWrite.Aliases.begin(), AE = SchedWrite.Aliases.end();
670 AI != AE; ++AI) {
671 const CodeGenSchedRW &AliasRW =
672 SchedModels.getSchedRW((*AI)->getValueAsDef("AliasRW"));
673 Record *ModelDef = AliasRW.TheDef->getValueAsDef("SchedModel");
674 if (&SchedModels.getProcModel(ModelDef) != &ProcModel)
675 continue;
676 if (AliasDef)
677 throw TGError(AliasRW.TheDef->getLoc(), "Multiple aliases "
678 "defined for processor " + ProcModel.ModelName +
679 " Ensure only one SchedAlias exists per RW.");
680 AliasDef = AliasRW.TheDef;
681 }
682 if (AliasDef && AliasDef->isSubClassOf("SchedWriteRes"))
683 return AliasDef;
Andrew Trick52c3a1d2012-09-17 22:18:48 +0000684
685 // Check this processor's list of write resources.
Andrew Trick92649882012-09-22 02:24:21 +0000686 Record *ResDef = 0;
Andrew Trick52c3a1d2012-09-17 22:18:48 +0000687 for (RecIter WRI = ProcModel.WriteResDefs.begin(),
688 WRE = ProcModel.WriteResDefs.end(); WRI != WRE; ++WRI) {
689 if (!(*WRI)->isSubClassOf("WriteRes"))
690 continue;
Andrew Trick92649882012-09-22 02:24:21 +0000691 if (AliasDef == (*WRI)->getValueAsDef("WriteType")
692 || SchedWrite.TheDef == (*WRI)->getValueAsDef("WriteType")) {
693 if (ResDef) {
694 throw TGError((*WRI)->getLoc(), "Resources are defined for both "
695 "SchedWrite and its alias on processor " +
696 ProcModel.ModelName);
697 }
698 ResDef = *WRI;
699 }
Andrew Trick52c3a1d2012-09-17 22:18:48 +0000700 }
Andrew Trick92649882012-09-22 02:24:21 +0000701 // TODO: If ProcModel has a base model (previous generation processor),
702 // then call FindWriteResources recursively with that model here.
703 if (!ResDef) {
704 throw TGError(ProcModel.ModelDef->getLoc(),
705 std::string("Processor does not define resources for ")
706 + SchedWrite.TheDef->getName());
707 }
708 return ResDef;
Andrew Trick52c3a1d2012-09-17 22:18:48 +0000709}
710
711/// Find the ReadAdvance record for the given SchedRead on this processor or
712/// return NULL.
Andrew Trick92649882012-09-22 02:24:21 +0000713Record *SubtargetEmitter::FindReadAdvance(const CodeGenSchedRW &SchedRead,
Andrew Trick52c3a1d2012-09-17 22:18:48 +0000714 const CodeGenProcModel &ProcModel) {
715 // Check for SchedReads that directly specify a ReadAdvance.
Andrew Trick92649882012-09-22 02:24:21 +0000716 if (SchedRead.TheDef->isSubClassOf("SchedReadAdvance"))
717 return SchedRead.TheDef;
718
719 // Check this processor's list of aliases for SchedRead.
720 Record *AliasDef = 0;
721 for (RecIter AI = SchedRead.Aliases.begin(), AE = SchedRead.Aliases.end();
722 AI != AE; ++AI) {
723 const CodeGenSchedRW &AliasRW =
724 SchedModels.getSchedRW((*AI)->getValueAsDef("AliasRW"));
725 Record *ModelDef = AliasRW.TheDef->getValueAsDef("SchedModel");
726 if (&SchedModels.getProcModel(ModelDef) != &ProcModel)
727 continue;
728 if (AliasDef)
729 throw TGError(AliasRW.TheDef->getLoc(), "Multiple aliases "
730 "defined for processor " + ProcModel.ModelName +
731 " Ensure only one SchedAlias exists per RW.");
732 AliasDef = AliasRW.TheDef;
733 }
734 if (AliasDef && AliasDef->isSubClassOf("SchedReadAdvance"))
735 return AliasDef;
Andrew Trick52c3a1d2012-09-17 22:18:48 +0000736
737 // Check this processor's ReadAdvanceList.
Andrew Trick92649882012-09-22 02:24:21 +0000738 Record *ResDef = 0;
Andrew Trick52c3a1d2012-09-17 22:18:48 +0000739 for (RecIter RAI = ProcModel.ReadAdvanceDefs.begin(),
740 RAE = ProcModel.ReadAdvanceDefs.end(); RAI != RAE; ++RAI) {
741 if (!(*RAI)->isSubClassOf("ReadAdvance"))
742 continue;
Andrew Trick92649882012-09-22 02:24:21 +0000743 if (AliasDef == (*RAI)->getValueAsDef("ReadType")
744 || SchedRead.TheDef == (*RAI)->getValueAsDef("ReadType")) {
745 if (ResDef) {
746 throw TGError((*RAI)->getLoc(), "Resources are defined for both "
747 "SchedRead and its alias on processor " +
748 ProcModel.ModelName);
749 }
750 ResDef = *RAI;
751 }
Andrew Trick52c3a1d2012-09-17 22:18:48 +0000752 }
Andrew Trick92649882012-09-22 02:24:21 +0000753 // TODO: If ProcModel has a base model (previous generation processor),
754 // then call FindReadAdvance recursively with that model here.
755 if (!ResDef && SchedRead.TheDef->getName() != "ReadDefault") {
Andrew Trick52c3a1d2012-09-17 22:18:48 +0000756 throw TGError(ProcModel.ModelDef->getLoc(),
757 std::string("Processor does not define resources for ")
Andrew Trick92649882012-09-22 02:24:21 +0000758 + SchedRead.TheDef->getName());
Andrew Trick52c3a1d2012-09-17 22:18:48 +0000759 }
Andrew Trick92649882012-09-22 02:24:21 +0000760 return ResDef;
Andrew Trick52c3a1d2012-09-17 22:18:48 +0000761}
762
763// Generate the SchedClass table for this processor and update global
764// tables. Must be called for each processor in order.
765void SubtargetEmitter::GenSchedClassTables(const CodeGenProcModel &ProcModel,
766 SchedClassTables &SchedTables) {
767 SchedTables.ProcSchedClasses.resize(SchedTables.ProcSchedClasses.size() + 1);
768 if (!ProcModel.hasInstrSchedModel())
769 return;
770
771 std::vector<MCSchedClassDesc> &SCTab = SchedTables.ProcSchedClasses.back();
772 for (CodeGenSchedModels::SchedClassIter SCI = SchedModels.schedClassBegin(),
773 SCE = SchedModels.schedClassEnd(); SCI != SCE; ++SCI) {
Andrew Trickfe05d982012-10-03 23:06:25 +0000774 DEBUG(SCI->dump(&SchedModels));
775
Andrew Trick52c3a1d2012-09-17 22:18:48 +0000776 SCTab.resize(SCTab.size() + 1);
777 MCSchedClassDesc &SCDesc = SCTab.back();
Andrew Tricke127dfd2012-09-18 03:18:56 +0000778 // SCDesc.Name is guarded by NDEBUG
Andrew Trick52c3a1d2012-09-17 22:18:48 +0000779 SCDesc.NumMicroOps = 0;
780 SCDesc.BeginGroup = false;
781 SCDesc.EndGroup = false;
782 SCDesc.WriteProcResIdx = 0;
783 SCDesc.WriteLatencyIdx = 0;
784 SCDesc.ReadAdvanceIdx = 0;
785
786 // A Variant SchedClass has no resources of its own.
787 if (!SCI->Transitions.empty()) {
788 SCDesc.NumMicroOps = MCSchedClassDesc::VariantNumMicroOps;
789 continue;
790 }
791
792 // Determine if the SchedClass is actually reachable on this processor. If
793 // not don't try to locate the processor resources, it will fail.
794 // If ProcIndices contains 0, this class applies to all processors.
795 assert(!SCI->ProcIndices.empty() && "expect at least one procidx");
796 if (SCI->ProcIndices[0] != 0) {
797 IdxIter PIPos = std::find(SCI->ProcIndices.begin(),
798 SCI->ProcIndices.end(), ProcModel.Index);
799 if (PIPos == SCI->ProcIndices.end())
800 continue;
801 }
802 IdxVec Writes = SCI->Writes;
803 IdxVec Reads = SCI->Reads;
804 if (SCI->ItinClassDef) {
805 assert(SCI->InstRWs.empty() && "ItinClass should not have InstRWs");
806 // Check this processor's itinerary class resources.
807 for (RecIter II = ProcModel.ItinRWDefs.begin(),
808 IE = ProcModel.ItinRWDefs.end(); II != IE; ++II) {
809 RecVec Matched = (*II)->getValueAsListOfDefs("MatchedItinClasses");
810 if (std::find(Matched.begin(), Matched.end(), SCI->ItinClassDef)
811 != Matched.end()) {
812 SchedModels.findRWs((*II)->getValueAsListOfDefs("OperandReadWrites"),
813 Writes, Reads);
814 break;
815 }
816 }
817 if (Writes.empty()) {
818 DEBUG(dbgs() << ProcModel.ItinsDef->getName()
819 << " does not have resources for itinerary class "
820 << SCI->ItinClassDef->getName() << '\n');
821 }
822 }
823 else if (!SCI->InstRWs.empty()) {
Andrew Trickfe05d982012-10-03 23:06:25 +0000824 // This class may have a default ReadWrite list which can be overriden by
825 // InstRW definitions.
Andrew Trick52c3a1d2012-09-17 22:18:48 +0000826 Record *RWDef = 0;
827 for (RecIter RWI = SCI->InstRWs.begin(), RWE = SCI->InstRWs.end();
828 RWI != RWE; ++RWI) {
829 Record *RWModelDef = (*RWI)->getValueAsDef("SchedModel");
830 if (&ProcModel == &SchedModels.getProcModel(RWModelDef)) {
831 RWDef = *RWI;
832 break;
833 }
834 }
835 if (RWDef) {
836 SchedModels.findRWs(RWDef->getValueAsListOfDefs("OperandReadWrites"),
837 Writes, Reads);
838 }
839 }
840 // Sum resources across all operand writes.
841 std::vector<MCWriteProcResEntry> WriteProcResources;
842 std::vector<MCWriteLatencyEntry> WriteLatencies;
Andrew Trick3b8fb642012-09-19 04:43:19 +0000843 std::vector<std::string> WriterNames;
Andrew Trick52c3a1d2012-09-17 22:18:48 +0000844 std::vector<MCReadAdvanceEntry> ReadAdvanceEntries;
845 for (IdxIter WI = Writes.begin(), WE = Writes.end(); WI != WE; ++WI) {
846 IdxVec WriteSeq;
847 SchedModels.expandRWSequence(*WI, WriteSeq, /*IsRead=*/false);
848
849 // For each operand, create a latency entry.
850 MCWriteLatencyEntry WLEntry;
851 WLEntry.Cycles = 0;
Andrew Trick3b8fb642012-09-19 04:43:19 +0000852 unsigned WriteID = WriteSeq.back();
853 WriterNames.push_back(SchedModels.getSchedWrite(WriteID).Name);
854 // If this Write is not referenced by a ReadAdvance, don't distinguish it
855 // from other WriteLatency entries.
856 if (!SchedModels.hasReadOfWrite(SchedModels.getSchedWrite(WriteID).TheDef)) {
857 WriteID = 0;
858 }
859 WLEntry.WriteResourceID = WriteID;
Andrew Trick52c3a1d2012-09-17 22:18:48 +0000860
861 for (IdxIter WSI = WriteSeq.begin(), WSE = WriteSeq.end();
862 WSI != WSE; ++WSI) {
863
Andrew Trick92649882012-09-22 02:24:21 +0000864 Record *WriteRes =
865 FindWriteResources(SchedModels.getSchedWrite(*WSI), ProcModel);
Andrew Trick52c3a1d2012-09-17 22:18:48 +0000866
867 // Mark the parent class as invalid for unsupported write types.
868 if (WriteRes->getValueAsBit("Unsupported")) {
869 SCDesc.NumMicroOps = MCSchedClassDesc::InvalidNumMicroOps;
870 break;
871 }
872 WLEntry.Cycles += WriteRes->getValueAsInt("Latency");
873 SCDesc.NumMicroOps += WriteRes->getValueAsInt("NumMicroOps");
874 SCDesc.BeginGroup |= WriteRes->getValueAsBit("BeginGroup");
875 SCDesc.EndGroup |= WriteRes->getValueAsBit("EndGroup");
876
877 // Create an entry for each ProcResource listed in WriteRes.
878 RecVec PRVec = WriteRes->getValueAsListOfDefs("ProcResources");
879 std::vector<int64_t> Cycles =
880 WriteRes->getValueAsListOfInts("ResourceCycles");
881 for (unsigned PRIdx = 0, PREnd = PRVec.size();
882 PRIdx != PREnd; ++PRIdx) {
883 MCWriteProcResEntry WPREntry;
884 WPREntry.ProcResourceIdx = ProcModel.getProcResourceIdx(PRVec[PRIdx]);
885 assert(WPREntry.ProcResourceIdx && "Bad ProcResourceIdx");
886 if (Cycles.size() > PRIdx)
887 WPREntry.Cycles = Cycles[PRIdx];
888 else
889 WPREntry.Cycles = 1;
890 WriteProcResources.push_back(WPREntry);
891 }
892 }
893 WriteLatencies.push_back(WLEntry);
894 }
895 // Create an entry for each operand Read in this SchedClass.
896 // Entries must be sorted first by UseIdx then by WriteResourceID.
897 for (unsigned UseIdx = 0, EndIdx = Reads.size();
898 UseIdx != EndIdx; ++UseIdx) {
Andrew Trick92649882012-09-22 02:24:21 +0000899 Record *ReadAdvance =
900 FindReadAdvance(SchedModels.getSchedRead(Reads[UseIdx]), ProcModel);
Andrew Trick52c3a1d2012-09-17 22:18:48 +0000901 if (!ReadAdvance)
902 continue;
903
904 // Mark the parent class as invalid for unsupported write types.
905 if (ReadAdvance->getValueAsBit("Unsupported")) {
906 SCDesc.NumMicroOps = MCSchedClassDesc::InvalidNumMicroOps;
907 break;
908 }
909 RecVec ValidWrites = ReadAdvance->getValueAsListOfDefs("ValidWrites");
910 IdxVec WriteIDs;
911 if (ValidWrites.empty())
912 WriteIDs.push_back(0);
913 else {
914 for (RecIter VWI = ValidWrites.begin(), VWE = ValidWrites.end();
915 VWI != VWE; ++VWI) {
916 WriteIDs.push_back(SchedModels.getSchedRWIdx(*VWI, /*IsRead=*/false));
917 }
918 }
919 std::sort(WriteIDs.begin(), WriteIDs.end());
920 for(IdxIter WI = WriteIDs.begin(), WE = WriteIDs.end(); WI != WE; ++WI) {
921 MCReadAdvanceEntry RAEntry;
922 RAEntry.UseIdx = UseIdx;
923 RAEntry.WriteResourceID = *WI;
924 RAEntry.Cycles = ReadAdvance->getValueAsInt("Cycles");
925 ReadAdvanceEntries.push_back(RAEntry);
926 }
927 }
928 if (SCDesc.NumMicroOps == MCSchedClassDesc::InvalidNumMicroOps) {
929 WriteProcResources.clear();
930 WriteLatencies.clear();
931 ReadAdvanceEntries.clear();
932 }
933 // Add the information for this SchedClass to the global tables using basic
934 // compression.
935 //
936 // WritePrecRes entries are sorted by ProcResIdx.
937 std::sort(WriteProcResources.begin(), WriteProcResources.end(),
938 LessWriteProcResources());
939
940 SCDesc.NumWriteProcResEntries = WriteProcResources.size();
941 std::vector<MCWriteProcResEntry>::iterator WPRPos =
942 std::search(SchedTables.WriteProcResources.begin(),
943 SchedTables.WriteProcResources.end(),
944 WriteProcResources.begin(), WriteProcResources.end());
945 if (WPRPos != SchedTables.WriteProcResources.end())
946 SCDesc.WriteProcResIdx = WPRPos - SchedTables.WriteProcResources.begin();
947 else {
948 SCDesc.WriteProcResIdx = SchedTables.WriteProcResources.size();
949 SchedTables.WriteProcResources.insert(WPRPos, WriteProcResources.begin(),
950 WriteProcResources.end());
951 }
952 // Latency entries must remain in operand order.
953 SCDesc.NumWriteLatencyEntries = WriteLatencies.size();
954 std::vector<MCWriteLatencyEntry>::iterator WLPos =
955 std::search(SchedTables.WriteLatencies.begin(),
956 SchedTables.WriteLatencies.end(),
957 WriteLatencies.begin(), WriteLatencies.end());
Andrew Trick3b8fb642012-09-19 04:43:19 +0000958 if (WLPos != SchedTables.WriteLatencies.end()) {
959 unsigned idx = WLPos - SchedTables.WriteLatencies.begin();
960 SCDesc.WriteLatencyIdx = idx;
961 for (unsigned i = 0, e = WriteLatencies.size(); i < e; ++i)
962 if (SchedTables.WriterNames[idx + i].find(WriterNames[i]) ==
963 std::string::npos) {
964 SchedTables.WriterNames[idx + i] += std::string("_") + WriterNames[i];
965 }
966 }
Andrew Trick52c3a1d2012-09-17 22:18:48 +0000967 else {
968 SCDesc.WriteLatencyIdx = SchedTables.WriteLatencies.size();
Andrew Trick3b8fb642012-09-19 04:43:19 +0000969 SchedTables.WriteLatencies.insert(SchedTables.WriteLatencies.end(),
970 WriteLatencies.begin(),
971 WriteLatencies.end());
972 SchedTables.WriterNames.insert(SchedTables.WriterNames.end(),
973 WriterNames.begin(), WriterNames.end());
Andrew Trick52c3a1d2012-09-17 22:18:48 +0000974 }
975 // ReadAdvanceEntries must remain in operand order.
976 SCDesc.NumReadAdvanceEntries = ReadAdvanceEntries.size();
977 std::vector<MCReadAdvanceEntry>::iterator RAPos =
978 std::search(SchedTables.ReadAdvanceEntries.begin(),
979 SchedTables.ReadAdvanceEntries.end(),
980 ReadAdvanceEntries.begin(), ReadAdvanceEntries.end());
981 if (RAPos != SchedTables.ReadAdvanceEntries.end())
982 SCDesc.ReadAdvanceIdx = RAPos - SchedTables.ReadAdvanceEntries.begin();
983 else {
984 SCDesc.ReadAdvanceIdx = SchedTables.ReadAdvanceEntries.size();
985 SchedTables.ReadAdvanceEntries.insert(RAPos, ReadAdvanceEntries.begin(),
986 ReadAdvanceEntries.end());
987 }
988 }
989}
990
Andrew Trick544c8802012-09-17 22:18:50 +0000991// Emit SchedClass tables for all processors and associated global tables.
992void SubtargetEmitter::EmitSchedClassTables(SchedClassTables &SchedTables,
993 raw_ostream &OS) {
994 // Emit global WriteProcResTable.
995 OS << "\n// {ProcResourceIdx, Cycles}\n"
996 << "extern const llvm::MCWriteProcResEntry "
997 << Target << "WriteProcResTable[] = {\n"
998 << " { 0, 0}, // Invalid\n";
999 for (unsigned WPRIdx = 1, WPREnd = SchedTables.WriteProcResources.size();
1000 WPRIdx != WPREnd; ++WPRIdx) {
1001 MCWriteProcResEntry &WPREntry = SchedTables.WriteProcResources[WPRIdx];
1002 OS << " {" << format("%2d", WPREntry.ProcResourceIdx) << ", "
1003 << format("%2d", WPREntry.Cycles) << "}";
1004 if (WPRIdx + 1 < WPREnd)
1005 OS << ',';
1006 OS << " // #" << WPRIdx << '\n';
1007 }
1008 OS << "}; // " << Target << "WriteProcResTable\n";
1009
1010 // Emit global WriteLatencyTable.
1011 OS << "\n// {Cycles, WriteResourceID}\n"
1012 << "extern const llvm::MCWriteLatencyEntry "
1013 << Target << "WriteLatencyTable[] = {\n"
1014 << " { 0, 0}, // Invalid\n";
1015 for (unsigned WLIdx = 1, WLEnd = SchedTables.WriteLatencies.size();
1016 WLIdx != WLEnd; ++WLIdx) {
1017 MCWriteLatencyEntry &WLEntry = SchedTables.WriteLatencies[WLIdx];
1018 OS << " {" << format("%2d", WLEntry.Cycles) << ", "
1019 << format("%2d", WLEntry.WriteResourceID) << "}";
1020 if (WLIdx + 1 < WLEnd)
1021 OS << ',';
Andrew Trick3b8fb642012-09-19 04:43:19 +00001022 OS << " // #" << WLIdx << " " << SchedTables.WriterNames[WLIdx] << '\n';
Andrew Trick544c8802012-09-17 22:18:50 +00001023 }
1024 OS << "}; // " << Target << "WriteLatencyTable\n";
1025
1026 // Emit global ReadAdvanceTable.
1027 OS << "\n// {UseIdx, WriteResourceID, Cycles}\n"
1028 << "extern const llvm::MCReadAdvanceEntry "
1029 << Target << "ReadAdvanceTable[] = {\n"
1030 << " {0, 0, 0}, // Invalid\n";
1031 for (unsigned RAIdx = 1, RAEnd = SchedTables.ReadAdvanceEntries.size();
1032 RAIdx != RAEnd; ++RAIdx) {
1033 MCReadAdvanceEntry &RAEntry = SchedTables.ReadAdvanceEntries[RAIdx];
1034 OS << " {" << RAEntry.UseIdx << ", "
1035 << format("%2d", RAEntry.WriteResourceID) << ", "
1036 << format("%2d", RAEntry.Cycles) << "}";
1037 if (RAIdx + 1 < RAEnd)
1038 OS << ',';
1039 OS << " // #" << RAIdx << '\n';
1040 }
1041 OS << "}; // " << Target << "ReadAdvanceTable\n";
1042
1043 // Emit a SchedClass table for each processor.
1044 for (CodeGenSchedModels::ProcIter PI = SchedModels.procModelBegin(),
1045 PE = SchedModels.procModelEnd(); PI != PE; ++PI) {
1046 if (!PI->hasInstrSchedModel())
1047 continue;
1048
1049 std::vector<MCSchedClassDesc> &SCTab =
1050 SchedTables.ProcSchedClasses[1 + PI - SchedModels.procModelBegin()];
1051
1052 OS << "\n// {Name, NumMicroOps, BeginGroup, EndGroup,"
1053 << " WriteProcResIdx,#, WriteLatencyIdx,#, ReadAdvanceIdx,#}\n";
1054 OS << "static const llvm::MCSchedClassDesc "
1055 << PI->ModelName << "SchedClasses[] = {\n";
1056
1057 // The first class is always invalid. We no way to distinguish it except by
1058 // name and position.
Andrew Tricke4095f92012-09-17 23:14:15 +00001059 assert(SchedModels.getSchedClass(0).Name == "NoItinerary"
Andrew Trick544c8802012-09-17 22:18:50 +00001060 && "invalid class not first");
1061 OS << " {DBGFIELD(\"InvalidSchedClass\") "
1062 << MCSchedClassDesc::InvalidNumMicroOps
1063 << ", 0, 0, 0, 0, 0, 0, 0, 0},\n";
1064
1065 for (unsigned SCIdx = 1, SCEnd = SCTab.size(); SCIdx != SCEnd; ++SCIdx) {
1066 MCSchedClassDesc &MCDesc = SCTab[SCIdx];
1067 const CodeGenSchedClass &SchedClass = SchedModels.getSchedClass(SCIdx);
1068 OS << " {DBGFIELD(\"" << SchedClass.Name << "\") ";
1069 if (SchedClass.Name.size() < 18)
1070 OS.indent(18 - SchedClass.Name.size());
1071 OS << MCDesc.NumMicroOps
1072 << ", " << MCDesc.BeginGroup << ", " << MCDesc.EndGroup
1073 << ", " << format("%2d", MCDesc.WriteProcResIdx)
1074 << ", " << MCDesc.NumWriteProcResEntries
1075 << ", " << format("%2d", MCDesc.WriteLatencyIdx)
1076 << ", " << MCDesc.NumWriteLatencyEntries
1077 << ", " << format("%2d", MCDesc.ReadAdvanceIdx)
1078 << ", " << MCDesc.NumReadAdvanceEntries << "}";
1079 if (SCIdx + 1 < SCEnd)
1080 OS << ',';
1081 OS << " // #" << SCIdx << '\n';
1082 }
1083 OS << "}; // " << PI->ModelName << "SchedClasses\n";
1084 }
1085}
1086
Andrew Trick2661b412012-07-07 04:00:00 +00001087void SubtargetEmitter::EmitProcessorModels(raw_ostream &OS) {
1088 // For each processor model.
1089 for (CodeGenSchedModels::ProcIter PI = SchedModels.procModelBegin(),
1090 PE = SchedModels.procModelEnd(); PI != PE; ++PI) {
Andrew Trick40096d22012-09-17 22:18:45 +00001091 // Emit processor resource table.
1092 if (PI->hasInstrSchedModel())
1093 EmitProcessorResources(*PI, OS);
1094 else if(!PI->ProcResourceDefs.empty())
1095 throw TGError(PI->ModelDef->getLoc(), "SchedMachineModel defines "
Andrew Trick52c3a1d2012-09-17 22:18:48 +00001096 "ProcResources without defining WriteRes SchedWriteRes");
Andrew Trick40096d22012-09-17 22:18:45 +00001097
Andrew Trickfc992992012-06-05 03:44:40 +00001098 // Begin processor itinerary properties
1099 OS << "\n";
Andrew Trick2661b412012-07-07 04:00:00 +00001100 OS << "static const llvm::MCSchedModel " << PI->ModelName << "(\n";
1101 EmitProcessorProp(OS, PI->ModelDef, "IssueWidth", ',');
1102 EmitProcessorProp(OS, PI->ModelDef, "MinLatency", ',');
1103 EmitProcessorProp(OS, PI->ModelDef, "LoadLatency", ',');
1104 EmitProcessorProp(OS, PI->ModelDef, "HighLatency", ',');
Andrew Trickd43b5c92012-08-08 02:44:16 +00001105 EmitProcessorProp(OS, PI->ModelDef, "MispredictPenalty", ',');
Andrew Tricke127dfd2012-09-18 03:18:56 +00001106 OS << " " << PI->Index << ", // Processor ID\n";
1107 if (PI->hasInstrSchedModel())
1108 OS << " " << PI->ModelName << "ProcResources" << ",\n"
1109 << " " << PI->ModelName << "SchedClasses" << ",\n"
1110 << " " << PI->ProcResourceDefs.size()+1 << ",\n"
1111 << " " << (SchedModels.schedClassEnd()
1112 - SchedModels.schedClassBegin()) << ",\n";
1113 else
1114 OS << " 0, 0, 0, 0, // No instruction-level machine model.\n";
Andrew Trick2661b412012-07-07 04:00:00 +00001115 if (SchedModels.hasItineraryClasses())
Andrew Trick40096d22012-09-17 22:18:45 +00001116 OS << " " << PI->ItinsDef->getName() << ");\n";
Andrew Trickd85934b2012-06-22 03:58:51 +00001117 else
Andrew Trick40096d22012-09-17 22:18:45 +00001118 OS << " 0); // No Itinerary\n";
Jim Laskey0d841e02005-10-27 19:47:21 +00001119 }
Jim Laskey10b1dd92005-10-31 17:16:01 +00001120}
1121
1122//
1123// EmitProcessorLookup - generate cpu name to itinerary lookup table.
1124//
Daniel Dunbar1a551802009-07-03 00:10:29 +00001125void SubtargetEmitter::EmitProcessorLookup(raw_ostream &OS) {
Jim Laskey10b1dd92005-10-31 17:16:01 +00001126 // Gather and sort processor information
1127 std::vector<Record*> ProcessorList =
1128 Records.getAllDerivedDefinitions("Processor");
Duraid Madina42d24c72005-12-30 14:56:37 +00001129 std::sort(ProcessorList.begin(), ProcessorList.end(), LessRecordFieldName());
Jim Laskey10b1dd92005-10-31 17:16:01 +00001130
1131 // Begin processor table
1132 OS << "\n";
1133 OS << "// Sorted (by key) array of itineraries for CPU subtype.\n"
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00001134 << "extern const llvm::SubtargetInfoKV "
Andrew Trick2661b412012-07-07 04:00:00 +00001135 << Target << "ProcSchedKV[] = {\n";
Andrew Trickda96cf22011-04-01 01:56:55 +00001136
Jim Laskey10b1dd92005-10-31 17:16:01 +00001137 // For each processor
1138 for (unsigned i = 0, N = ProcessorList.size(); i < N;) {
1139 // Next processor
1140 Record *Processor = ProcessorList[i];
1141
Bill Wendling4222d802007-05-04 20:38:40 +00001142 const std::string &Name = Processor->getValueAsString("Name");
Andrew Trick2661b412012-07-07 04:00:00 +00001143 const std::string &ProcModelName =
Andrew Trick48605c32012-09-15 00:19:57 +00001144 SchedModels.getModelForProc(Processor).ModelName;
Andrew Trickda96cf22011-04-01 01:56:55 +00001145
Jim Laskey10b1dd92005-10-31 17:16:01 +00001146 // Emit as { "cpu", procinit },
Andrew Trick40096d22012-09-17 22:18:45 +00001147 OS << " { \"" << Name << "\", (const void *)&" << ProcModelName << " }";
Andrew Trickda96cf22011-04-01 01:56:55 +00001148
Jim Laskey10b1dd92005-10-31 17:16:01 +00001149 // Depending on ''if more in the list'' emit comma
1150 if (++i < N) OS << ",";
Andrew Trickda96cf22011-04-01 01:56:55 +00001151
Jim Laskey10b1dd92005-10-31 17:16:01 +00001152 OS << "\n";
1153 }
Andrew Trickda96cf22011-04-01 01:56:55 +00001154
Jim Laskey10b1dd92005-10-31 17:16:01 +00001155 // End processor table
1156 OS << "};\n";
Jim Laskey0d841e02005-10-27 19:47:21 +00001157}
1158
1159//
Andrew Trick2661b412012-07-07 04:00:00 +00001160// EmitSchedModel - Emits all scheduling model tables, folding common patterns.
Jim Laskey0d841e02005-10-27 19:47:21 +00001161//
Andrew Trick2661b412012-07-07 04:00:00 +00001162void SubtargetEmitter::EmitSchedModel(raw_ostream &OS) {
Andrew Trick40096d22012-09-17 22:18:45 +00001163 OS << "#ifdef DBGFIELD\n"
1164 << "#error \"<target>GenSubtargetInfo.inc requires a DBGFIELD macro\"\n"
1165 << "#endif\n"
1166 << "#ifndef NDEBUG\n"
1167 << "#define DBGFIELD(x) x,\n"
1168 << "#else\n"
1169 << "#define DBGFIELD(x)\n"
1170 << "#endif\n";
1171
Andrew Trick2661b412012-07-07 04:00:00 +00001172 if (SchedModels.hasItineraryClasses()) {
1173 std::vector<std::vector<InstrItinerary> > ProcItinLists;
Jim Laskey6cee6302005-11-01 20:06:59 +00001174 // Emit the stage data
Andrew Trick2661b412012-07-07 04:00:00 +00001175 EmitStageAndOperandCycleData(OS, ProcItinLists);
1176 EmitItineraries(OS, ProcItinLists);
Jim Laskey6cee6302005-11-01 20:06:59 +00001177 }
Andrew Trick544c8802012-09-17 22:18:50 +00001178 OS << "\n// ===============================================================\n"
1179 << "// Data tables for the new per-operand machine model.\n";
Andrew Trick40096d22012-09-17 22:18:45 +00001180
Andrew Trick52c3a1d2012-09-17 22:18:48 +00001181 SchedClassTables SchedTables;
1182 for (CodeGenSchedModels::ProcIter PI = SchedModels.procModelBegin(),
1183 PE = SchedModels.procModelEnd(); PI != PE; ++PI) {
1184 GenSchedClassTables(*PI, SchedTables);
1185 }
Andrew Trick544c8802012-09-17 22:18:50 +00001186 EmitSchedClassTables(SchedTables, OS);
1187
1188 // Emit the processor machine model
1189 EmitProcessorModels(OS);
1190 // Emit the processor lookup data
1191 EmitProcessorLookup(OS);
Andrew Trick52c3a1d2012-09-17 22:18:48 +00001192
Andrew Trick40096d22012-09-17 22:18:45 +00001193 OS << "#undef DBGFIELD";
Jim Laskey0d841e02005-10-27 19:47:21 +00001194}
1195
Andrew Trick4d2d1c42012-09-18 03:41:43 +00001196void SubtargetEmitter::EmitSchedModelHelpers(std::string ClassName,
1197 raw_ostream &OS) {
1198 OS << "unsigned " << ClassName
1199 << "\n::resolveSchedClass(unsigned SchedClass, const MachineInstr *MI,"
1200 << " const TargetSchedModel *SchedModel) const {\n";
1201
1202 std::vector<Record*> Prologs = Records.getAllDerivedDefinitions("PredicateProlog");
1203 std::sort(Prologs.begin(), Prologs.end(), LessRecord());
1204 for (std::vector<Record*>::const_iterator
1205 PI = Prologs.begin(), PE = Prologs.end(); PI != PE; ++PI) {
1206 OS << (*PI)->getValueAsString("Code") << '\n';
1207 }
1208 IdxVec VariantClasses;
1209 for (CodeGenSchedModels::SchedClassIter SCI = SchedModels.schedClassBegin(),
1210 SCE = SchedModels.schedClassEnd(); SCI != SCE; ++SCI) {
1211 if (SCI->Transitions.empty())
1212 continue;
1213 VariantClasses.push_back(SCI - SchedModels.schedClassBegin());
1214 }
1215 if (!VariantClasses.empty()) {
1216 OS << " switch (SchedClass) {\n";
1217 for (IdxIter VCI = VariantClasses.begin(), VCE = VariantClasses.end();
1218 VCI != VCE; ++VCI) {
1219 const CodeGenSchedClass &SC = SchedModels.getSchedClass(*VCI);
1220 OS << " case " << *VCI << ": // " << SC.Name << '\n';
1221 IdxVec ProcIndices;
1222 for (std::vector<CodeGenSchedTransition>::const_iterator
1223 TI = SC.Transitions.begin(), TE = SC.Transitions.end();
1224 TI != TE; ++TI) {
1225 IdxVec PI;
1226 std::set_union(TI->ProcIndices.begin(), TI->ProcIndices.end(),
1227 ProcIndices.begin(), ProcIndices.end(),
1228 std::back_inserter(PI));
1229 ProcIndices.swap(PI);
1230 }
1231 for (IdxIter PI = ProcIndices.begin(), PE = ProcIndices.end();
1232 PI != PE; ++PI) {
1233 OS << " ";
1234 if (*PI != 0)
1235 OS << "if (SchedModel->getProcessorID() == " << *PI << ") ";
1236 OS << "{ // " << (SchedModels.procModelBegin() + *PI)->ModelName
1237 << '\n';
1238 for (std::vector<CodeGenSchedTransition>::const_iterator
1239 TI = SC.Transitions.begin(), TE = SC.Transitions.end();
1240 TI != TE; ++TI) {
1241 OS << " if (";
1242 if (*PI != 0 && !std::count(TI->ProcIndices.begin(),
1243 TI->ProcIndices.end(), *PI)) {
1244 continue;
1245 }
1246 for (RecIter RI = TI->PredTerm.begin(), RE = TI->PredTerm.end();
1247 RI != RE; ++RI) {
1248 if (RI != TI->PredTerm.begin())
1249 OS << "\n && ";
1250 OS << "(" << (*RI)->getValueAsString("Predicate") << ")";
1251 }
1252 OS << ")\n"
1253 << " return " << TI->ToClassIdx << "; // "
1254 << SchedModels.getSchedClass(TI->ToClassIdx).Name << '\n';
1255 }
1256 OS << " }\n";
1257 if (*PI == 0)
1258 break;
1259 }
1260 unsigned SCIdx = 0;
1261 if (SC.ItinClassDef)
1262 SCIdx = SchedModels.getSchedClassIdxForItin(SC.ItinClassDef);
1263 else
1264 SCIdx = SchedModels.findSchedClassIdx(SC.Writes, SC.Reads);
1265 if (SCIdx != *VCI)
1266 OS << " return " << SCIdx << ";\n";
1267 OS << " break;\n";
1268 }
1269 OS << " };\n";
1270 }
1271 OS << " report_fatal_error(\"Expected a variant SchedClass\");\n"
1272 << "} // " << ClassName << "::resolveSchedClass\n";
1273}
1274
Jim Laskey0d841e02005-10-27 19:47:21 +00001275//
Jim Laskey581a8f72005-10-26 17:30:34 +00001276// ParseFeaturesFunction - Produces a subtarget specific function for parsing
1277// the subtarget features string.
1278//
Evan Cheng94214702011-07-01 20:45:01 +00001279void SubtargetEmitter::ParseFeaturesFunction(raw_ostream &OS,
1280 unsigned NumFeatures,
1281 unsigned NumProcs) {
Jim Laskeyf7bcde02005-10-28 21:47:29 +00001282 std::vector<Record*> Features =
1283 Records.getAllDerivedDefinitions("SubtargetFeature");
Duraid Madina42d24c72005-12-30 14:56:37 +00001284 std::sort(Features.begin(), Features.end(), LessRecord());
Jim Laskey581a8f72005-10-26 17:30:34 +00001285
Andrew Trickda96cf22011-04-01 01:56:55 +00001286 OS << "// ParseSubtargetFeatures - Parses features string setting specified\n"
1287 << "// subtarget options.\n"
Evan Cheng276365d2011-06-30 01:53:36 +00001288 << "void llvm::";
Jim Laskey581a8f72005-10-26 17:30:34 +00001289 OS << Target;
Evan Cheng0ddff1b2011-07-07 07:07:08 +00001290 OS << "Subtarget::ParseSubtargetFeatures(StringRef CPU, StringRef FS) {\n"
David Greenef0fd3af2010-01-05 17:47:41 +00001291 << " DEBUG(dbgs() << \"\\nFeatures:\" << FS);\n"
Hal Finkel3f696e52012-06-12 04:21:36 +00001292 << " DEBUG(dbgs() << \"\\nCPU:\" << CPU << \"\\n\\n\");\n";
Evan Cheng94214702011-07-01 20:45:01 +00001293
1294 if (Features.empty()) {
1295 OS << "}\n";
1296 return;
1297 }
1298
Andrew Trick34aadd62012-09-18 05:33:15 +00001299 OS << " InitMCProcessorInfo(CPU, FS);\n"
1300 << " uint64_t Bits = getFeatureBits();\n";
Bill Wendling4222d802007-05-04 20:38:40 +00001301
Jim Laskeyf7bcde02005-10-28 21:47:29 +00001302 for (unsigned i = 0; i < Features.size(); i++) {
1303 // Next record
1304 Record *R = Features[i];
Bill Wendling4222d802007-05-04 20:38:40 +00001305 const std::string &Instance = R->getName();
1306 const std::string &Value = R->getValueAsString("Value");
1307 const std::string &Attribute = R->getValueAsString("Attribute");
Evan Cheng19c95502006-01-27 08:09:42 +00001308
Dale Johannesendb01c8b2008-02-14 23:35:16 +00001309 if (Value=="true" || Value=="false")
Evan Cheng0ddff1b2011-07-07 07:07:08 +00001310 OS << " if ((Bits & " << Target << "::"
1311 << Instance << ") != 0) "
Dale Johannesendb01c8b2008-02-14 23:35:16 +00001312 << Attribute << " = " << Value << ";\n";
1313 else
Evan Cheng0ddff1b2011-07-07 07:07:08 +00001314 OS << " if ((Bits & " << Target << "::"
1315 << Instance << ") != 0 && "
Evan Cheng94214702011-07-01 20:45:01 +00001316 << Attribute << " < " << Value << ") "
1317 << Attribute << " = " << Value << ";\n";
Jim Laskey6cee6302005-11-01 20:06:59 +00001318 }
Anton Korobeynikov41a02432009-05-23 19:50:50 +00001319
Evan Cheng276365d2011-06-30 01:53:36 +00001320 OS << "}\n";
Jim Laskey581a8f72005-10-26 17:30:34 +00001321}
1322
Anton Korobeynikov41a02432009-05-23 19:50:50 +00001323//
Jim Laskey4bb9cbb2005-10-21 19:00:04 +00001324// SubtargetEmitter::run - Main subtarget enumeration emitter.
1325//
Daniel Dunbar1a551802009-07-03 00:10:29 +00001326void SubtargetEmitter::run(raw_ostream &OS) {
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +00001327 emitSourceFileHeader("Subtarget Enumeration Source Fragment", OS);
Jim Laskey4bb9cbb2005-10-21 19:00:04 +00001328
Evan Chengebdeeab2011-07-08 01:53:10 +00001329 OS << "\n#ifdef GET_SUBTARGETINFO_ENUM\n";
1330 OS << "#undef GET_SUBTARGETINFO_ENUM\n";
1331
1332 OS << "namespace llvm {\n";
1333 Enumeration(OS, "SubtargetFeature", true);
1334 OS << "} // End llvm namespace \n";
1335 OS << "#endif // GET_SUBTARGETINFO_ENUM\n\n";
1336
Evan Cheng94214702011-07-01 20:45:01 +00001337 OS << "\n#ifdef GET_SUBTARGETINFO_MC_DESC\n";
1338 OS << "#undef GET_SUBTARGETINFO_MC_DESC\n";
Anton Korobeynikov928eb492010-04-18 20:31:01 +00001339
Evan Cheng94214702011-07-01 20:45:01 +00001340 OS << "namespace llvm {\n";
Evan Chengc60f9b72011-07-14 20:59:42 +00001341#if 0
1342 OS << "namespace {\n";
1343#endif
Evan Cheng94214702011-07-01 20:45:01 +00001344 unsigned NumFeatures = FeatureKeyValues(OS);
Evan Chengc60f9b72011-07-14 20:59:42 +00001345 OS << "\n";
Evan Cheng94214702011-07-01 20:45:01 +00001346 unsigned NumProcs = CPUKeyValues(OS);
Evan Chengc60f9b72011-07-14 20:59:42 +00001347 OS << "\n";
Andrew Trick2661b412012-07-07 04:00:00 +00001348 EmitSchedModel(OS);
Evan Chengc60f9b72011-07-14 20:59:42 +00001349 OS << "\n";
1350#if 0
1351 OS << "}\n";
1352#endif
Evan Cheng94214702011-07-01 20:45:01 +00001353
1354 // MCInstrInfo initialization routine.
1355 OS << "static inline void Init" << Target
Evan Cheng59ee62d2011-07-11 03:57:24 +00001356 << "MCSubtargetInfo(MCSubtargetInfo *II, "
1357 << "StringRef TT, StringRef CPU, StringRef FS) {\n";
1358 OS << " II->InitMCSubtargetInfo(TT, CPU, FS, ";
Evan Cheng94214702011-07-01 20:45:01 +00001359 if (NumFeatures)
1360 OS << Target << "FeatureKV, ";
1361 else
1362 OS << "0, ";
1363 if (NumProcs)
1364 OS << Target << "SubTypeKV, ";
1365 else
1366 OS << "0, ";
Andrew Trick544c8802012-09-17 22:18:50 +00001367 OS << '\n'; OS.indent(22);
Andrew Tricke127dfd2012-09-18 03:18:56 +00001368 OS << Target << "ProcSchedKV, "
1369 << Target << "WriteProcResTable, "
1370 << Target << "WriteLatencyTable, "
1371 << Target << "ReadAdvanceTable, ";
Andrew Trick2661b412012-07-07 04:00:00 +00001372 if (SchedModels.hasItineraryClasses()) {
Andrew Tricke127dfd2012-09-18 03:18:56 +00001373 OS << '\n'; OS.indent(22);
1374 OS << Target << "Stages, "
Evan Cheng94214702011-07-01 20:45:01 +00001375 << Target << "OperandCycles, "
Andrew Tricka11a6282012-07-07 03:59:48 +00001376 << Target << "ForwardingPaths, ";
Evan Cheng94214702011-07-01 20:45:01 +00001377 } else
Andrew Tricke127dfd2012-09-18 03:18:56 +00001378 OS << "0, 0, 0, ";
Evan Cheng94214702011-07-01 20:45:01 +00001379 OS << NumFeatures << ", " << NumProcs << ");\n}\n\n";
1380
1381 OS << "} // End llvm namespace \n";
1382
1383 OS << "#endif // GET_SUBTARGETINFO_MC_DESC\n\n";
1384
1385 OS << "\n#ifdef GET_SUBTARGETINFO_TARGET_DESC\n";
1386 OS << "#undef GET_SUBTARGETINFO_TARGET_DESC\n";
1387
1388 OS << "#include \"llvm/Support/Debug.h\"\n";
1389 OS << "#include \"llvm/Support/raw_ostream.h\"\n";
1390 ParseFeaturesFunction(OS, NumFeatures, NumProcs);
1391
1392 OS << "#endif // GET_SUBTARGETINFO_TARGET_DESC\n\n";
1393
Evan Cheng5b1b44892011-07-01 21:01:15 +00001394 // Create a TargetSubtargetInfo subclass to hide the MC layer initialization.
Evan Cheng94214702011-07-01 20:45:01 +00001395 OS << "\n#ifdef GET_SUBTARGETINFO_HEADER\n";
1396 OS << "#undef GET_SUBTARGETINFO_HEADER\n";
1397
1398 std::string ClassName = Target + "GenSubtargetInfo";
1399 OS << "namespace llvm {\n";
Anshuman Dasguptadc81e5d2011-12-01 21:10:21 +00001400 OS << "class DFAPacketizer;\n";
Evan Cheng5b1b44892011-07-01 21:01:15 +00001401 OS << "struct " << ClassName << " : public TargetSubtargetInfo {\n"
Evan Cheng0ddff1b2011-07-07 07:07:08 +00001402 << " explicit " << ClassName << "(StringRef TT, StringRef CPU, "
1403 << "StringRef FS);\n"
Anshuman Dasguptadc81e5d2011-12-01 21:10:21 +00001404 << "public:\n"
Andrew Trick4d2d1c42012-09-18 03:41:43 +00001405 << " unsigned resolveSchedClass(unsigned SchedClass, const MachineInstr *DefMI,"
1406 << " const TargetSchedModel *SchedModel) const;\n"
Sebastian Pop464f3a32011-12-06 17:34:16 +00001407 << " DFAPacketizer *createDFAPacketizer(const InstrItineraryData *IID)"
Anshuman Dasguptadc81e5d2011-12-01 21:10:21 +00001408 << " const;\n"
Evan Cheng94214702011-07-01 20:45:01 +00001409 << "};\n";
1410 OS << "} // End llvm namespace \n";
1411
1412 OS << "#endif // GET_SUBTARGETINFO_HEADER\n\n";
1413
1414 OS << "\n#ifdef GET_SUBTARGETINFO_CTOR\n";
1415 OS << "#undef GET_SUBTARGETINFO_CTOR\n";
1416
Andrew Trickee290ba2012-09-18 03:32:57 +00001417 OS << "#include \"llvm/CodeGen/TargetSchedule.h\"\n";
Evan Cheng94214702011-07-01 20:45:01 +00001418 OS << "namespace llvm {\n";
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00001419 OS << "extern const llvm::SubtargetFeatureKV " << Target << "FeatureKV[];\n";
1420 OS << "extern const llvm::SubtargetFeatureKV " << Target << "SubTypeKV[];\n";
Andrew Trick544c8802012-09-17 22:18:50 +00001421 OS << "extern const llvm::SubtargetInfoKV " << Target << "ProcSchedKV[];\n";
1422 OS << "extern const llvm::MCWriteProcResEntry "
1423 << Target << "WriteProcResTable[];\n";
1424 OS << "extern const llvm::MCWriteLatencyEntry "
1425 << Target << "WriteLatencyTable[];\n";
1426 OS << "extern const llvm::MCReadAdvanceEntry "
1427 << Target << "ReadAdvanceTable[];\n";
1428
Andrew Trick2661b412012-07-07 04:00:00 +00001429 if (SchedModels.hasItineraryClasses()) {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00001430 OS << "extern const llvm::InstrStage " << Target << "Stages[];\n";
1431 OS << "extern const unsigned " << Target << "OperandCycles[];\n";
Andrew Tricka11a6282012-07-07 03:59:48 +00001432 OS << "extern const unsigned " << Target << "ForwardingPaths[];\n";
Evan Chengc60f9b72011-07-14 20:59:42 +00001433 }
1434
Evan Cheng0ddff1b2011-07-07 07:07:08 +00001435 OS << ClassName << "::" << ClassName << "(StringRef TT, StringRef CPU, "
1436 << "StringRef FS)\n"
Evan Cheng5b1b44892011-07-01 21:01:15 +00001437 << " : TargetSubtargetInfo() {\n"
Evan Cheng59ee62d2011-07-11 03:57:24 +00001438 << " InitMCSubtargetInfo(TT, CPU, FS, ";
Evan Cheng94214702011-07-01 20:45:01 +00001439 if (NumFeatures)
1440 OS << Target << "FeatureKV, ";
1441 else
1442 OS << "0, ";
1443 if (NumProcs)
1444 OS << Target << "SubTypeKV, ";
1445 else
1446 OS << "0, ";
Andrew Tricke127dfd2012-09-18 03:18:56 +00001447 OS << '\n'; OS.indent(22);
1448 OS << Target << "ProcSchedKV, "
1449 << Target << "WriteProcResTable, "
1450 << Target << "WriteLatencyTable, "
1451 << Target << "ReadAdvanceTable, ";
1452 OS << '\n'; OS.indent(22);
Andrew Trick2661b412012-07-07 04:00:00 +00001453 if (SchedModels.hasItineraryClasses()) {
Andrew Tricke127dfd2012-09-18 03:18:56 +00001454 OS << Target << "Stages, "
Evan Cheng94214702011-07-01 20:45:01 +00001455 << Target << "OperandCycles, "
Andrew Tricka11a6282012-07-07 03:59:48 +00001456 << Target << "ForwardingPaths, ";
Evan Cheng94214702011-07-01 20:45:01 +00001457 } else
Andrew Tricke127dfd2012-09-18 03:18:56 +00001458 OS << "0, 0, 0, ";
Evan Cheng94214702011-07-01 20:45:01 +00001459 OS << NumFeatures << ", " << NumProcs << ");\n}\n\n";
Andrew Trick544c8802012-09-17 22:18:50 +00001460
Andrew Trick4d2d1c42012-09-18 03:41:43 +00001461 EmitSchedModelHelpers(ClassName, OS);
1462
Evan Cheng94214702011-07-01 20:45:01 +00001463 OS << "} // End llvm namespace \n";
1464
1465 OS << "#endif // GET_SUBTARGETINFO_CTOR\n\n";
Jim Laskey4bb9cbb2005-10-21 19:00:04 +00001466}
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +00001467
1468namespace llvm {
1469
1470void EmitSubtarget(RecordKeeper &RK, raw_ostream &OS) {
Andrew Trick2661b412012-07-07 04:00:00 +00001471 CodeGenTarget CGTarget(RK);
1472 SubtargetEmitter(RK, CGTarget).run(OS);
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +00001473}
1474
1475} // End llvm namespace