blob: a80ce6108f0a32ed02d3746657cbec059629bfb4 [file] [log] [blame]
Jim Laskeycfda85a2005-10-21 19:00:04 +00001//===- SubtargetEmitter.cpp - Generate subtarget enumerations -------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner8adcd9f2007-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 Laskeycfda85a2005-10-21 19:00:04 +00007//
8//===----------------------------------------------------------------------===//
9//
Chris Lattner73fbe142006-03-03 02:04:07 +000010// This tablegen backend emits subtarget enumerations.
Jim Laskeycfda85a2005-10-21 19:00:04 +000011//
12//===----------------------------------------------------------------------===//
13
Jim Laskeycfda85a2005-10-21 19:00:04 +000014#include "CodeGenTarget.h"
Andrew Trick87255e32012-07-07 04:00:00 +000015#include "CodeGenSchedule.h"
Eugene Zelenko75259bb2016-05-17 17:04:23 +000016#include "llvm/ADT/SmallPtrSet.h"
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000017#include "llvm/ADT/STLExtras.h"
Chandler Carruth91d19d82012-12-04 10:37:14 +000018#include "llvm/ADT/StringExtras.h"
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000019#include "llvm/ADT/StringRef.h"
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +000020#include "llvm/MC/MCInstrItineraries.h"
Eugene Zelenko75259bb2016-05-17 17:04:23 +000021#include "llvm/MC/MCSchedule.h"
Michael Kupersteindb0712f2015-05-26 10:47:10 +000022#include "llvm/MC/SubtargetFeature.h"
Chandler Carruth91d19d82012-12-04 10:37:14 +000023#include "llvm/Support/Debug.h"
24#include "llvm/Support/Format.h"
Eugene Zelenko75259bb2016-05-17 17:04:23 +000025#include "llvm/Support/raw_ostream.h"
Andrew Trick23f3c652012-09-17 22:18:45 +000026#include "llvm/TableGen/Error.h"
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +000027#include "llvm/TableGen/Record.h"
28#include "llvm/TableGen/TableGenBackend.h"
Jeff Cohenb0aa47b2005-10-28 01:43:09 +000029#include <algorithm>
Eugene Zelenko75259bb2016-05-17 17:04:23 +000030#include <cassert>
31#include <cstdint>
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000032#include <iterator>
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +000033#include <map>
34#include <string>
35#include <vector>
Hans Wennborg083ca9b2015-10-06 23:24:35 +000036
Jim Laskeycfda85a2005-10-21 19:00:04 +000037using namespace llvm;
38
Chandler Carruth97acce22014-04-22 03:06:00 +000039#define DEBUG_TYPE "subtarget-emitter"
40
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +000041namespace {
Eugene Zelenko75259bb2016-05-17 17:04:23 +000042
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +000043class SubtargetEmitter {
Andrew Trick9ef08822012-09-17 22:18:48 +000044 // Each processor has a SchedClassDesc table with an entry for each SchedClass.
45 // The SchedClassDesc table indexes into a global write resource table, write
46 // latency table, and read advance table.
47 struct SchedClassTables {
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000048 std::vector<std::vector<MCSchedClassDesc>> ProcSchedClasses;
Andrew Trick9ef08822012-09-17 22:18:48 +000049 std::vector<MCWriteProcResEntry> WriteProcResources;
50 std::vector<MCWriteLatencyEntry> WriteLatencies;
Andrew Trickcfe222c2012-09-19 04:43:19 +000051 std::vector<std::string> WriterNames;
Andrew Trick9ef08822012-09-17 22:18:48 +000052 std::vector<MCReadAdvanceEntry> ReadAdvanceEntries;
53
54 // Reserve an invalid entry at index 0
55 SchedClassTables() {
56 ProcSchedClasses.resize(1);
57 WriteProcResources.resize(1);
58 WriteLatencies.resize(1);
Andrew Trickcfe222c2012-09-19 04:43:19 +000059 WriterNames.push_back("InvalidWrite");
Andrew Trick9ef08822012-09-17 22:18:48 +000060 ReadAdvanceEntries.resize(1);
61 }
62 };
63
64 struct LessWriteProcResources {
65 bool operator()(const MCWriteProcResEntry &LHS,
66 const MCWriteProcResEntry &RHS) {
67 return LHS.ProcResourceIdx < RHS.ProcResourceIdx;
68 }
69 };
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +000070
Krzysztof Parzyszek788e7682017-09-14 20:44:20 +000071 const CodeGenTarget &TGT;
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +000072 RecordKeeper &Records;
Andrew Trick87255e32012-07-07 04:00:00 +000073 CodeGenSchedModels &SchedModels;
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +000074 std::string Target;
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +000075
Craig Topper094bbca2016-02-14 05:22:01 +000076 void Enumeration(raw_ostream &OS);
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +000077 unsigned FeatureKeyValues(raw_ostream &OS);
78 unsigned CPUKeyValues(raw_ostream &OS);
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +000079 void FormItineraryStageString(const std::string &Names,
80 Record *ItinData, std::string &ItinString,
81 unsigned &NStages);
82 void FormItineraryOperandCycleString(Record *ItinData, std::string &ItinString,
83 unsigned &NOperandCycles);
84 void FormItineraryBypassString(const std::string &Names,
85 Record *ItinData,
86 std::string &ItinString, unsigned NOperandCycles);
Andrew Trick87255e32012-07-07 04:00:00 +000087 void EmitStageAndOperandCycleData(raw_ostream &OS,
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000088 std::vector<std::vector<InstrItinerary>>
Andrew Trick87255e32012-07-07 04:00:00 +000089 &ProcItinLists);
90 void EmitItineraries(raw_ostream &OS,
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000091 std::vector<std::vector<InstrItinerary>>
Andrew Trick87255e32012-07-07 04:00:00 +000092 &ProcItinLists);
Andrea Di Biagio378d75a2018-04-04 11:53:13 +000093 unsigned EmitRegisterFileTables(const CodeGenProcModel &ProcModel,
94 raw_ostream &OS);
95 void EmitExtraProcessorInfo(const CodeGenProcModel &ProcModel,
96 raw_ostream &OS);
Mehdi Amini32986ed2016-10-04 23:47:33 +000097 void EmitProcessorProp(raw_ostream &OS, const Record *R, StringRef Name,
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +000098 char Separator);
Clement Courbet39911e22018-02-08 08:46:48 +000099 void EmitProcessorResourceSubUnits(const CodeGenProcModel &ProcModel,
100 raw_ostream &OS);
Andrew Trick23f3c652012-09-17 22:18:45 +0000101 void EmitProcessorResources(const CodeGenProcModel &ProcModel,
102 raw_ostream &OS);
Andrew Trick9257b8f2012-09-22 02:24:21 +0000103 Record *FindWriteResources(const CodeGenSchedRW &SchedWrite,
Andrew Trick9ef08822012-09-17 22:18:48 +0000104 const CodeGenProcModel &ProcModel);
Andrew Trick9257b8f2012-09-22 02:24:21 +0000105 Record *FindReadAdvance(const CodeGenSchedRW &SchedRead,
106 const CodeGenProcModel &ProcModel);
Andrew Trick4e67cba2013-03-14 21:21:50 +0000107 void ExpandProcResources(RecVec &PRVec, std::vector<int64_t> &Cycles,
108 const CodeGenProcModel &ProcModel);
Andrew Trick9ef08822012-09-17 22:18:48 +0000109 void GenSchedClassTables(const CodeGenProcModel &ProcModel,
110 SchedClassTables &SchedTables);
Andrew Tricka72fca62012-09-17 22:18:50 +0000111 void EmitSchedClassTables(SchedClassTables &SchedTables, raw_ostream &OS);
Andrew Trick87255e32012-07-07 04:00:00 +0000112 void EmitProcessorModels(raw_ostream &OS);
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +0000113 void EmitProcessorLookup(raw_ostream &OS);
Benjamin Kramerc321e532016-06-08 19:09:22 +0000114 void EmitSchedModelHelpers(const std::string &ClassName, raw_ostream &OS);
Andrew Trick87255e32012-07-07 04:00:00 +0000115 void EmitSchedModel(raw_ostream &OS);
Krzysztof Parzyszek788e7682017-09-14 20:44:20 +0000116 void EmitHwModeCheck(const std::string &ClassName, raw_ostream &OS);
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +0000117 void ParseFeaturesFunction(raw_ostream &OS, unsigned NumFeatures,
118 unsigned NumProcs);
119
120public:
Krzysztof Parzyszek788e7682017-09-14 20:44:20 +0000121 SubtargetEmitter(RecordKeeper &R, CodeGenTarget &TGT)
122 : TGT(TGT), Records(R), SchedModels(TGT.getSchedModels()),
123 Target(TGT.getName()) {}
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +0000124
125 void run(raw_ostream &o);
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +0000126};
Eugene Zelenko75259bb2016-05-17 17:04:23 +0000127
Hans Wennborg083ca9b2015-10-06 23:24:35 +0000128} // end anonymous namespace
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +0000129
Jim Laskeya1beea62005-10-22 07:59:56 +0000130//
Jim Laskeya2b52352005-10-26 17:30:34 +0000131// Enumeration - Emit the specified class as an enumeration.
Jim Laskey1b7369b2005-10-25 15:16:36 +0000132//
Craig Topper094bbca2016-02-14 05:22:01 +0000133void SubtargetEmitter::Enumeration(raw_ostream &OS) {
Jim Laskey19595752005-10-28 15:20:43 +0000134 // Get all records of class and sort
Craig Topper094bbca2016-02-14 05:22:01 +0000135 std::vector<Record*> DefList =
136 Records.getAllDerivedDefinitions("SubtargetFeature");
Duraid Madina018da4f2005-12-30 14:56:37 +0000137 std::sort(DefList.begin(), DefList.end(), LessRecord());
Jim Laskey1b7369b2005-10-25 15:16:36 +0000138
Evan Chenga2e61292011-04-15 19:35:46 +0000139 unsigned N = DefList.size();
Evan Cheng54b68e32011-07-01 20:45:01 +0000140 if (N == 0)
141 return;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000142 if (N > MAX_SUBTARGET_FEATURES)
143 PrintFatalError("Too many subtarget features! Bump MAX_SUBTARGET_FEATURES.");
Evan Chenga2e61292011-04-15 19:35:46 +0000144
Evan Cheng54b68e32011-07-01 20:45:01 +0000145 OS << "namespace " << Target << " {\n";
146
Craig Topperbcdb0f22016-02-13 17:58:14 +0000147 // Open enumeration.
Craig Topper2d45c1d2016-02-13 06:03:29 +0000148 OS << "enum {\n";
Evan Cheng54b68e32011-07-01 20:45:01 +0000149
Reid Kleckner294fa7a2015-03-09 20:23:14 +0000150 // For each record
Craig Topperdf1285b2017-10-24 15:50:53 +0000151 for (unsigned i = 0; i < N; ++i) {
Reid Kleckner294fa7a2015-03-09 20:23:14 +0000152 // Next record
153 Record *Def = DefList[i];
Andrew Trickdb6ed642011-04-01 01:56:55 +0000154
Reid Kleckner294fa7a2015-03-09 20:23:14 +0000155 // Get and emit name
Craig Topperdf1285b2017-10-24 15:50:53 +0000156 OS << " " << Def->getName() << " = " << i << ",\n";
Jim Laskey1b7369b2005-10-25 15:16:36 +0000157 }
Andrew Trickdb6ed642011-04-01 01:56:55 +0000158
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000159 // Close enumeration and namespace
Eugene Zelenko75259bb2016-05-17 17:04:23 +0000160 OS << "};\n";
161 OS << "} // end namespace " << Target << "\n";
Jim Laskey1b7369b2005-10-25 15:16:36 +0000162}
163
164//
Bill Wendlinge6182262007-05-04 20:38:40 +0000165// FeatureKeyValues - Emit data of all the subtarget features. Used by the
166// command line.
Jim Laskey1b7369b2005-10-25 15:16:36 +0000167//
Evan Cheng54b68e32011-07-01 20:45:01 +0000168unsigned SubtargetEmitter::FeatureKeyValues(raw_ostream &OS) {
Jim Laskey19595752005-10-28 15:20:43 +0000169 // Gather and sort all the features
Jim Laskeydffe5972005-10-28 21:47:29 +0000170 std::vector<Record*> FeatureList =
171 Records.getAllDerivedDefinitions("SubtargetFeature");
Evan Cheng54b68e32011-07-01 20:45:01 +0000172
173 if (FeatureList.empty())
174 return 0;
175
Jim Grosbach56938af2008-09-11 17:05:32 +0000176 std::sort(FeatureList.begin(), FeatureList.end(), LessRecordFieldName());
Jim Laskey1b7369b2005-10-25 15:16:36 +0000177
Jim Laskey19595752005-10-28 15:20:43 +0000178 // Begin feature table
Jim Laskeya2b52352005-10-26 17:30:34 +0000179 OS << "// Sorted (by key) array of values for CPU features.\n"
Benjamin Kramer0d6d0982011-10-22 16:50:00 +0000180 << "extern const llvm::SubtargetFeatureKV " << Target
181 << "FeatureKV[] = {\n";
Andrew Trickdb6ed642011-04-01 01:56:55 +0000182
Jim Laskey19595752005-10-28 15:20:43 +0000183 // For each feature
Evan Cheng54b68e32011-07-01 20:45:01 +0000184 unsigned NumFeatures = 0;
Jim Laskey3f7d0472006-12-12 20:55:58 +0000185 for (unsigned i = 0, N = FeatureList.size(); i < N; ++i) {
Jim Laskeydffe5972005-10-28 21:47:29 +0000186 // Next feature
187 Record *Feature = FeatureList[i];
188
Craig Topperbcd3c372017-05-31 21:12:46 +0000189 StringRef Name = Feature->getName();
190 StringRef CommandLineName = Feature->getValueAsString("Name");
191 StringRef Desc = Feature->getValueAsString("Desc");
Andrew Trickdb6ed642011-04-01 01:56:55 +0000192
Jim Laskey3f7d0472006-12-12 20:55:58 +0000193 if (CommandLineName.empty()) continue;
Andrew Trickdb6ed642011-04-01 01:56:55 +0000194
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000195 // Emit as { "feature", "description", { featureEnum }, { i1 , i2 , ... , in } }
Jim Laskey1b7369b2005-10-25 15:16:36 +0000196 OS << " { "
Jim Laskeydffe5972005-10-28 21:47:29 +0000197 << "\"" << CommandLineName << "\", "
Jim Laskey1b7369b2005-10-25 15:16:36 +0000198 << "\"" << Desc << "\", "
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000199 << "{ " << Target << "::" << Name << " }, ";
Bill Wendlinge6182262007-05-04 20:38:40 +0000200
Craig Topper37eeb322018-03-23 00:02:45 +0000201 RecVec ImpliesList = Feature->getValueAsListOfDefs("Implies");
Andrew Trickdb6ed642011-04-01 01:56:55 +0000202
Craig Topper4ceea0a2016-01-03 08:57:41 +0000203 OS << "{";
204 for (unsigned j = 0, M = ImpliesList.size(); j < M;) {
205 OS << " " << Target << "::" << ImpliesList[j]->getName();
206 if (++j < M) OS << ",";
Bill Wendlinge6182262007-05-04 20:38:40 +0000207 }
Craig Topperdf1285b2017-10-24 15:50:53 +0000208 OS << " } },\n";
Evan Cheng54b68e32011-07-01 20:45:01 +0000209 ++NumFeatures;
Jim Laskey1b7369b2005-10-25 15:16:36 +0000210 }
Andrew Trickdb6ed642011-04-01 01:56:55 +0000211
Jim Laskey19595752005-10-28 15:20:43 +0000212 // End feature table
Jim Laskey1b7369b2005-10-25 15:16:36 +0000213 OS << "};\n";
214
Evan Cheng54b68e32011-07-01 20:45:01 +0000215 return NumFeatures;
Jim Laskey1b7369b2005-10-25 15:16:36 +0000216}
217
218//
219// CPUKeyValues - Emit data of all the subtarget processors. Used by command
220// line.
221//
Evan Cheng54b68e32011-07-01 20:45:01 +0000222unsigned SubtargetEmitter::CPUKeyValues(raw_ostream &OS) {
Jim Laskey19595752005-10-28 15:20:43 +0000223 // Gather and sort processor information
Jim Laskeydffe5972005-10-28 21:47:29 +0000224 std::vector<Record*> ProcessorList =
225 Records.getAllDerivedDefinitions("Processor");
Duraid Madina018da4f2005-12-30 14:56:37 +0000226 std::sort(ProcessorList.begin(), ProcessorList.end(), LessRecordFieldName());
Jim Laskey1b7369b2005-10-25 15:16:36 +0000227
Jim Laskey19595752005-10-28 15:20:43 +0000228 // Begin processor table
Jim Laskeya2b52352005-10-26 17:30:34 +0000229 OS << "// Sorted (by key) array of values for CPU subtype.\n"
Benjamin Kramer0d6d0982011-10-22 16:50:00 +0000230 << "extern const llvm::SubtargetFeatureKV " << Target
231 << "SubTypeKV[] = {\n";
Andrew Trickdb6ed642011-04-01 01:56:55 +0000232
Jim Laskey19595752005-10-28 15:20:43 +0000233 // For each processor
Craig Topperdf1285b2017-10-24 15:50:53 +0000234 for (Record *Processor : ProcessorList) {
Craig Topperbcd3c372017-05-31 21:12:46 +0000235 StringRef Name = Processor->getValueAsString("Name");
Craig Topper37eeb322018-03-23 00:02:45 +0000236 RecVec FeatureList = Processor->getValueAsListOfDefs("Features");
Andrew Trickdb6ed642011-04-01 01:56:55 +0000237
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000238 // Emit as { "cpu", "description", { f1 , f2 , ... fn } },
Jim Laskey1b7369b2005-10-25 15:16:36 +0000239 OS << " { "
240 << "\"" << Name << "\", "
241 << "\"Select the " << Name << " processor\", ";
Andrew Trickdb6ed642011-04-01 01:56:55 +0000242
Craig Topper4ceea0a2016-01-03 08:57:41 +0000243 OS << "{";
244 for (unsigned j = 0, M = FeatureList.size(); j < M;) {
245 OS << " " << Target << "::" << FeatureList[j]->getName();
246 if (++j < M) OS << ",";
Jim Laskey1b7369b2005-10-25 15:16:36 +0000247 }
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000248 // The { } is for the "implies" section of this data structure.
Craig Topperdf1285b2017-10-24 15:50:53 +0000249 OS << " }, { } },\n";
Jim Laskey1b7369b2005-10-25 15:16:36 +0000250 }
Andrew Trickdb6ed642011-04-01 01:56:55 +0000251
Jim Laskey19595752005-10-28 15:20:43 +0000252 // End processor table
Jim Laskey1b7369b2005-10-25 15:16:36 +0000253 OS << "};\n";
254
Evan Cheng54b68e32011-07-01 20:45:01 +0000255 return ProcessorList.size();
Jim Laskey1b7369b2005-10-25 15:16:36 +0000256}
Jim Laskeya1beea62005-10-22 07:59:56 +0000257
Jim Laskeya2b52352005-10-26 17:30:34 +0000258//
David Goodwind813cbf2009-08-17 16:02:57 +0000259// FormItineraryStageString - Compose a string containing the stage
260// data initialization for the specified itinerary. N is the number
261// of stages.
Jim Laskey86f002c2005-10-27 19:47:21 +0000262//
Anton Korobeynikov7d62e332010-04-18 20:31:01 +0000263void SubtargetEmitter::FormItineraryStageString(const std::string &Name,
264 Record *ItinData,
David Goodwind813cbf2009-08-17 16:02:57 +0000265 std::string &ItinString,
266 unsigned &NStages) {
Jim Laskeydffe5972005-10-28 21:47:29 +0000267 // Get states list
Craig Topper37eeb322018-03-23 00:02:45 +0000268 RecVec StageList = ItinData->getValueAsListOfDefs("Stages");
Jim Laskey19595752005-10-28 15:20:43 +0000269
270 // For each stage
Jim Laskeydffe5972005-10-28 21:47:29 +0000271 unsigned N = NStages = StageList.size();
Christopher Lamb8996dce2007-04-22 09:04:24 +0000272 for (unsigned i = 0; i < N;) {
Jim Laskeydffe5972005-10-28 21:47:29 +0000273 // Next stage
Bill Wendlinge6182262007-05-04 20:38:40 +0000274 const Record *Stage = StageList[i];
Andrew Trickdb6ed642011-04-01 01:56:55 +0000275
Anton Korobeynikov0bdc6342010-04-07 18:19:32 +0000276 // Form string as ,{ cycles, u1 | u2 | ... | un, timeinc, kind }
Jim Laskey86f002c2005-10-27 19:47:21 +0000277 int Cycles = Stage->getValueAsInt("Cycles");
Jim Laskeyd6d3afb2005-11-03 22:47:41 +0000278 ItinString += " { " + itostr(Cycles) + ", ";
Andrew Trickdb6ed642011-04-01 01:56:55 +0000279
Jim Laskeydffe5972005-10-28 21:47:29 +0000280 // Get unit list
Craig Topper37eeb322018-03-23 00:02:45 +0000281 RecVec UnitList = Stage->getValueAsListOfDefs("Units");
Andrew Trickdb6ed642011-04-01 01:56:55 +0000282
Jim Laskey19595752005-10-28 15:20:43 +0000283 // For each unit
Jim Laskeydffe5972005-10-28 21:47:29 +0000284 for (unsigned j = 0, M = UnitList.size(); j < M;) {
Jim Laskeydffe5972005-10-28 21:47:29 +0000285 // Add name and bitwise or
Matthias Braun4a86d452016-12-04 05:48:16 +0000286 ItinString += Name + "FU::" + UnitList[j]->getName().str();
Jim Laskeydffe5972005-10-28 21:47:29 +0000287 if (++j < M) ItinString += " | ";
Jim Laskey86f002c2005-10-27 19:47:21 +0000288 }
Andrew Trickdb6ed642011-04-01 01:56:55 +0000289
David Goodwinb369ee42009-08-12 18:31:53 +0000290 int TimeInc = Stage->getValueAsInt("TimeInc");
291 ItinString += ", " + itostr(TimeInc);
292
Anton Korobeynikov0bdc6342010-04-07 18:19:32 +0000293 int Kind = Stage->getValueAsInt("Kind");
294 ItinString += ", (llvm::InstrStage::ReservationKinds)" + itostr(Kind);
295
Jim Laskey19595752005-10-28 15:20:43 +0000296 // Close off stage
297 ItinString += " }";
Christopher Lamb8996dce2007-04-22 09:04:24 +0000298 if (++i < N) ItinString += ", ";
Jim Laskey86f002c2005-10-27 19:47:21 +0000299 }
Jim Laskey86f002c2005-10-27 19:47:21 +0000300}
301
302//
David Goodwind813cbf2009-08-17 16:02:57 +0000303// FormItineraryOperandCycleString - Compose a string containing the
304// operand cycle initialization for the specified itinerary. N is the
305// number of operands that has cycles specified.
Jim Laskey86f002c2005-10-27 19:47:21 +0000306//
David Goodwind813cbf2009-08-17 16:02:57 +0000307void SubtargetEmitter::FormItineraryOperandCycleString(Record *ItinData,
308 std::string &ItinString, unsigned &NOperandCycles) {
309 // Get operand cycle list
Craig Topper37eeb322018-03-23 00:02:45 +0000310 std::vector<int64_t> OperandCycleList =
David Goodwind813cbf2009-08-17 16:02:57 +0000311 ItinData->getValueAsListOfInts("OperandCycles");
312
313 // For each operand cycle
314 unsigned N = NOperandCycles = OperandCycleList.size();
315 for (unsigned i = 0; i < N;) {
316 // Next operand cycle
317 const int OCycle = OperandCycleList[i];
Andrew Trickdb6ed642011-04-01 01:56:55 +0000318
David Goodwind813cbf2009-08-17 16:02:57 +0000319 ItinString += " " + itostr(OCycle);
320 if (++i < N) ItinString += ", ";
321 }
322}
323
Evan Cheng0097dd02010-09-28 23:50:49 +0000324void SubtargetEmitter::FormItineraryBypassString(const std::string &Name,
325 Record *ItinData,
326 std::string &ItinString,
327 unsigned NOperandCycles) {
Craig Topper37eeb322018-03-23 00:02:45 +0000328 RecVec BypassList = ItinData->getValueAsListOfDefs("Bypasses");
Evan Cheng0097dd02010-09-28 23:50:49 +0000329 unsigned N = BypassList.size();
Evan Cheng4a010fd2010-09-29 22:42:35 +0000330 unsigned i = 0;
331 for (; i < N;) {
Matthias Braun4a86d452016-12-04 05:48:16 +0000332 ItinString += Name + "Bypass::" + BypassList[i]->getName().str();
Evan Cheng4a010fd2010-09-29 22:42:35 +0000333 if (++i < NOperandCycles) ItinString += ", ";
Evan Cheng0097dd02010-09-28 23:50:49 +0000334 }
Evan Cheng4a010fd2010-09-29 22:42:35 +0000335 for (; i < NOperandCycles;) {
Evan Cheng0097dd02010-09-28 23:50:49 +0000336 ItinString += " 0";
Evan Cheng4a010fd2010-09-29 22:42:35 +0000337 if (++i < NOperandCycles) ItinString += ", ";
Evan Cheng0097dd02010-09-28 23:50:49 +0000338 }
339}
340
David Goodwind813cbf2009-08-17 16:02:57 +0000341//
Andrew Trick87255e32012-07-07 04:00:00 +0000342// EmitStageAndOperandCycleData - Generate unique itinerary stages and operand
343// cycle tables. Create a list of InstrItinerary objects (ProcItinLists) indexed
344// by CodeGenSchedClass::Index.
David Goodwind813cbf2009-08-17 16:02:57 +0000345//
Andrew Trick87255e32012-07-07 04:00:00 +0000346void SubtargetEmitter::
347EmitStageAndOperandCycleData(raw_ostream &OS,
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000348 std::vector<std::vector<InstrItinerary>>
Andrew Trick87255e32012-07-07 04:00:00 +0000349 &ProcItinLists) {
Andrew Trickfb982dd2012-07-09 20:43:03 +0000350 // Multiple processor models may share an itinerary record. Emit it once.
351 SmallPtrSet<Record*, 8> ItinsDefSet;
352
Anton Korobeynikov7d62e332010-04-18 20:31:01 +0000353 // Emit functional units for all the itineraries.
Craig Topper29c55dcb2016-02-13 06:03:32 +0000354 for (const CodeGenProcModel &ProcModel : SchedModels.procModels()) {
Anton Korobeynikov7d62e332010-04-18 20:31:01 +0000355
Craig Topper29c55dcb2016-02-13 06:03:32 +0000356 if (!ItinsDefSet.insert(ProcModel.ItinsDef).second)
Andrew Trickfb982dd2012-07-09 20:43:03 +0000357 continue;
358
Craig Topper37eeb322018-03-23 00:02:45 +0000359 RecVec FUs = ProcModel.ItinsDef->getValueAsListOfDefs("FU");
Anton Korobeynikov7d62e332010-04-18 20:31:01 +0000360 if (FUs.empty())
361 continue;
362
Alexander Shaposhnikovd968f6f2017-07-05 20:14:54 +0000363 StringRef Name = ProcModel.ItinsDef->getName();
Andrew Trick87255e32012-07-07 04:00:00 +0000364 OS << "\n// Functional units for \"" << Name << "\"\n"
Anton Korobeynikov7d62e332010-04-18 20:31:01 +0000365 << "namespace " << Name << "FU {\n";
366
367 for (unsigned j = 0, FUN = FUs.size(); j < FUN; ++j)
Hal Finkel8db55472012-06-22 20:27:13 +0000368 OS << " const unsigned " << FUs[j]->getName()
369 << " = 1 << " << j << ";\n";
Anton Korobeynikov7d62e332010-04-18 20:31:01 +0000370
Eugene Zelenko75259bb2016-05-17 17:04:23 +0000371 OS << "} // end namespace " << Name << "FU\n";
Evan Cheng0097dd02010-09-28 23:50:49 +0000372
Craig Topper37eeb322018-03-23 00:02:45 +0000373 RecVec BPs = ProcModel.ItinsDef->getValueAsListOfDefs("BP");
Alexander Kornienko8c0809c2015-01-15 11:41:30 +0000374 if (!BPs.empty()) {
Sylvestre Ledru543f15b2018-03-17 17:30:08 +0000375 OS << "\n// Pipeline forwarding paths for itineraries \"" << Name
Evan Cheng4a010fd2010-09-29 22:42:35 +0000376 << "\"\n" << "namespace " << Name << "Bypass {\n";
Evan Cheng0097dd02010-09-28 23:50:49 +0000377
Benjamin Kramer0d6d0982011-10-22 16:50:00 +0000378 OS << " const unsigned NoBypass = 0;\n";
Evan Cheng4a010fd2010-09-29 22:42:35 +0000379 for (unsigned j = 0, BPN = BPs.size(); j < BPN; ++j)
Benjamin Kramer0d6d0982011-10-22 16:50:00 +0000380 OS << " const unsigned " << BPs[j]->getName()
Evan Cheng4a010fd2010-09-29 22:42:35 +0000381 << " = 1 << " << j << ";\n";
Evan Cheng0097dd02010-09-28 23:50:49 +0000382
Eugene Zelenko75259bb2016-05-17 17:04:23 +0000383 OS << "} // end namespace " << Name << "Bypass\n";
Evan Cheng4a010fd2010-09-29 22:42:35 +0000384 }
Anton Korobeynikov7d62e332010-04-18 20:31:01 +0000385 }
386
Jim Laskey19595752005-10-28 15:20:43 +0000387 // Begin stages table
Benjamin Kramer0d6d0982011-10-22 16:50:00 +0000388 std::string StageTable = "\nextern const llvm::InstrStage " + Target +
389 "Stages[] = {\n";
Anton Korobeynikov0bdc6342010-04-07 18:19:32 +0000390 StageTable += " { 0, 0, 0, llvm::InstrStage::Required }, // No itinerary\n";
Andrew Trickdb6ed642011-04-01 01:56:55 +0000391
David Goodwind813cbf2009-08-17 16:02:57 +0000392 // Begin operand cycle table
Benjamin Kramer0d6d0982011-10-22 16:50:00 +0000393 std::string OperandCycleTable = "extern const unsigned " + Target +
Evan Cheng54b68e32011-07-01 20:45:01 +0000394 "OperandCycles[] = {\n";
David Goodwind813cbf2009-08-17 16:02:57 +0000395 OperandCycleTable += " 0, // No itinerary\n";
Evan Cheng0097dd02010-09-28 23:50:49 +0000396
397 // Begin pipeline bypass table
Benjamin Kramer0d6d0982011-10-22 16:50:00 +0000398 std::string BypassTable = "extern const unsigned " + Target +
Andrew Trick030e2f82012-07-07 03:59:48 +0000399 "ForwardingPaths[] = {\n";
Andrew Trick87255e32012-07-07 04:00:00 +0000400 BypassTable += " 0, // No itinerary\n";
Andrew Trickdb6ed642011-04-01 01:56:55 +0000401
Andrew Trick87255e32012-07-07 04:00:00 +0000402 // For each Itinerary across all processors, add a unique entry to the stages,
Geoff Berryb2cfea52017-05-08 15:33:08 +0000403 // operand cycles, and pipeline bypass tables. Then add the new Itinerary
Andrew Trick87255e32012-07-07 04:00:00 +0000404 // object with computed offsets to the ProcItinLists result.
David Goodwind813cbf2009-08-17 16:02:57 +0000405 unsigned StageCount = 1, OperandCycleCount = 1;
Evan Cheng4a010fd2010-09-29 22:42:35 +0000406 std::map<std::string, unsigned> ItinStageMap, ItinOperandMap;
Craig Topper29c55dcb2016-02-13 06:03:32 +0000407 for (const CodeGenProcModel &ProcModel : SchedModels.procModels()) {
Andrew Trick87255e32012-07-07 04:00:00 +0000408 // Add process itinerary to the list.
409 ProcItinLists.resize(ProcItinLists.size()+1);
Andrew Trickdb6ed642011-04-01 01:56:55 +0000410
Andrew Trick87255e32012-07-07 04:00:00 +0000411 // If this processor defines no itineraries, then leave the itinerary list
412 // empty.
413 std::vector<InstrItinerary> &ItinList = ProcItinLists.back();
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000414 if (!ProcModel.hasItineraries())
Andrew Trick9c302672012-06-22 03:58:51 +0000415 continue;
Andrew Trick9c302672012-06-22 03:58:51 +0000416
Alexander Shaposhnikovd968f6f2017-07-05 20:14:54 +0000417 StringRef Name = ProcModel.ItinsDef->getName();
Andrew Trickdb6ed642011-04-01 01:56:55 +0000418
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000419 ItinList.resize(SchedModels.numInstrSchedClasses());
420 assert(ProcModel.ItinDefList.size() == ItinList.size() && "bad Itins");
421
422 for (unsigned SchedClassIdx = 0, SchedClassEnd = ItinList.size();
Andrew Trick87255e32012-07-07 04:00:00 +0000423 SchedClassIdx < SchedClassEnd; ++SchedClassIdx) {
424
Jim Laskeydffe5972005-10-28 21:47:29 +0000425 // Next itinerary data
Andrew Trick87255e32012-07-07 04:00:00 +0000426 Record *ItinData = ProcModel.ItinDefList[SchedClassIdx];
Andrew Trickdb6ed642011-04-01 01:56:55 +0000427
Jim Laskey19595752005-10-28 15:20:43 +0000428 // Get string and stage count
David Goodwind813cbf2009-08-17 16:02:57 +0000429 std::string ItinStageString;
Andrew Trick87255e32012-07-07 04:00:00 +0000430 unsigned NStages = 0;
431 if (ItinData)
432 FormItineraryStageString(Name, ItinData, ItinStageString, NStages);
Jim Laskey86f002c2005-10-27 19:47:21 +0000433
David Goodwind813cbf2009-08-17 16:02:57 +0000434 // Get string and operand cycle count
435 std::string ItinOperandCycleString;
Andrew Trick87255e32012-07-07 04:00:00 +0000436 unsigned NOperandCycles = 0;
Evan Cheng0097dd02010-09-28 23:50:49 +0000437 std::string ItinBypassString;
Andrew Trick87255e32012-07-07 04:00:00 +0000438 if (ItinData) {
439 FormItineraryOperandCycleString(ItinData, ItinOperandCycleString,
440 NOperandCycles);
441
442 FormItineraryBypassString(Name, ItinData, ItinBypassString,
443 NOperandCycles);
444 }
Evan Cheng0097dd02010-09-28 23:50:49 +0000445
David Goodwind813cbf2009-08-17 16:02:57 +0000446 // Check to see if stage already exists and create if it doesn't
Benjamin Kramerb941aba2018-02-23 19:32:56 +0000447 uint16_t FindStage = 0;
David Goodwind813cbf2009-08-17 16:02:57 +0000448 if (NStages > 0) {
449 FindStage = ItinStageMap[ItinStageString];
450 if (FindStage == 0) {
Andrew Trick8a05f662011-04-01 02:22:47 +0000451 // Emit as { cycles, u1 | u2 | ... | un, timeinc }, // indices
452 StageTable += ItinStageString + ", // " + itostr(StageCount);
453 if (NStages > 1)
454 StageTable += "-" + itostr(StageCount + NStages - 1);
455 StageTable += "\n";
David Goodwind813cbf2009-08-17 16:02:57 +0000456 // Record Itin class number.
457 ItinStageMap[ItinStageString] = FindStage = StageCount;
458 StageCount += NStages;
David Goodwind813cbf2009-08-17 16:02:57 +0000459 }
460 }
Andrew Trickdb6ed642011-04-01 01:56:55 +0000461
David Goodwind813cbf2009-08-17 16:02:57 +0000462 // Check to see if operand cycle already exists and create if it doesn't
Benjamin Kramerb941aba2018-02-23 19:32:56 +0000463 uint16_t FindOperandCycle = 0;
David Goodwind813cbf2009-08-17 16:02:57 +0000464 if (NOperandCycles > 0) {
Evan Cheng4a010fd2010-09-29 22:42:35 +0000465 std::string ItinOperandString = ItinOperandCycleString+ItinBypassString;
466 FindOperandCycle = ItinOperandMap[ItinOperandString];
David Goodwind813cbf2009-08-17 16:02:57 +0000467 if (FindOperandCycle == 0) {
468 // Emit as cycle, // index
Andrew Trick8a05f662011-04-01 02:22:47 +0000469 OperandCycleTable += ItinOperandCycleString + ", // ";
470 std::string OperandIdxComment = itostr(OperandCycleCount);
471 if (NOperandCycles > 1)
472 OperandIdxComment += "-"
473 + itostr(OperandCycleCount + NOperandCycles - 1);
474 OperandCycleTable += OperandIdxComment + "\n";
David Goodwind813cbf2009-08-17 16:02:57 +0000475 // Record Itin class number.
Andrew Trickdb6ed642011-04-01 01:56:55 +0000476 ItinOperandMap[ItinOperandCycleString] =
David Goodwind813cbf2009-08-17 16:02:57 +0000477 FindOperandCycle = OperandCycleCount;
Evan Cheng0097dd02010-09-28 23:50:49 +0000478 // Emit as bypass, // index
Andrew Trick8a05f662011-04-01 02:22:47 +0000479 BypassTable += ItinBypassString + ", // " + OperandIdxComment + "\n";
David Goodwind813cbf2009-08-17 16:02:57 +0000480 OperandCycleCount += NOperandCycles;
David Goodwind813cbf2009-08-17 16:02:57 +0000481 }
Jim Laskey86f002c2005-10-27 19:47:21 +0000482 }
Andrew Trickdb6ed642011-04-01 01:56:55 +0000483
Evan Cheng367a5df2010-09-09 18:18:55 +0000484 // Set up itinerary as location and location + stage count
Benjamin Kramerb941aba2018-02-23 19:32:56 +0000485 int16_t NumUOps = ItinData ? ItinData->getValueAsInt("NumMicroOps") : 0;
486 InstrItinerary Intinerary = {
487 NumUOps,
488 FindStage,
489 uint16_t(FindStage + NStages),
490 FindOperandCycle,
491 uint16_t(FindOperandCycle + NOperandCycles),
492 };
Evan Cheng367a5df2010-09-09 18:18:55 +0000493
Jim Laskey19595752005-10-28 15:20:43 +0000494 // Inject - empty slots will be 0, 0
Andrew Trick87255e32012-07-07 04:00:00 +0000495 ItinList[SchedClassIdx] = Intinerary;
Jim Laskey86f002c2005-10-27 19:47:21 +0000496 }
Jim Laskey86f002c2005-10-27 19:47:21 +0000497 }
Evan Cheng0097dd02010-09-28 23:50:49 +0000498
Jim Laskeyd6d3afb2005-11-03 22:47:41 +0000499 // Closing stage
Andrew Trick87255e32012-07-07 04:00:00 +0000500 StageTable += " { 0, 0, 0, llvm::InstrStage::Required } // End stages\n";
David Goodwind813cbf2009-08-17 16:02:57 +0000501 StageTable += "};\n";
502
503 // Closing operand cycles
Andrew Trick87255e32012-07-07 04:00:00 +0000504 OperandCycleTable += " 0 // End operand cycles\n";
David Goodwind813cbf2009-08-17 16:02:57 +0000505 OperandCycleTable += "};\n";
506
Andrew Trick87255e32012-07-07 04:00:00 +0000507 BypassTable += " 0 // End bypass tables\n";
Evan Cheng0097dd02010-09-28 23:50:49 +0000508 BypassTable += "};\n";
509
David Goodwind813cbf2009-08-17 16:02:57 +0000510 // Emit tables.
511 OS << StageTable;
512 OS << OperandCycleTable;
Evan Cheng0097dd02010-09-28 23:50:49 +0000513 OS << BypassTable;
Jim Laskey86f002c2005-10-27 19:47:21 +0000514}
515
Andrew Trick87255e32012-07-07 04:00:00 +0000516//
517// EmitProcessorData - Generate data for processor itineraries that were
518// computed during EmitStageAndOperandCycleData(). ProcItinLists lists all
519// Itineraries for each processor. The Itinerary lists are indexed on
520// CodeGenSchedClass::Index.
521//
522void SubtargetEmitter::
523EmitItineraries(raw_ostream &OS,
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000524 std::vector<std::vector<InstrItinerary>> &ProcItinLists) {
Andrew Trickfb982dd2012-07-09 20:43:03 +0000525 // Multiple processor models may share an itinerary record. Emit it once.
526 SmallPtrSet<Record*, 8> ItinsDefSet;
527
Andrew Trick87255e32012-07-07 04:00:00 +0000528 // For each processor's machine model
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000529 std::vector<std::vector<InstrItinerary>>::iterator
Andrew Trick87255e32012-07-07 04:00:00 +0000530 ProcItinListsIter = ProcItinLists.begin();
531 for (CodeGenSchedModels::ProcIter PI = SchedModels.procModelBegin(),
Andrew Trick76686492012-09-15 00:19:57 +0000532 PE = SchedModels.procModelEnd(); PI != PE; ++PI, ++ProcItinListsIter) {
Andrew Trickfb982dd2012-07-09 20:43:03 +0000533
Andrew Trick87255e32012-07-07 04:00:00 +0000534 Record *ItinsDef = PI->ItinsDef;
David Blaikie70573dc2014-11-19 07:49:26 +0000535 if (!ItinsDefSet.insert(ItinsDef).second)
Andrew Trickfb982dd2012-07-09 20:43:03 +0000536 continue;
Andrew Trick87255e32012-07-07 04:00:00 +0000537
Andrew Trick87255e32012-07-07 04:00:00 +0000538 // Get the itinerary list for the processor.
539 assert(ProcItinListsIter != ProcItinLists.end() && "bad iterator");
Andrew Trick76686492012-09-15 00:19:57 +0000540 std::vector<InstrItinerary> &ItinList = *ProcItinListsIter;
Andrew Trick87255e32012-07-07 04:00:00 +0000541
Pete Cooperc0eb1532014-09-02 23:23:34 +0000542 // Empty itineraries aren't referenced anywhere in the tablegen output
543 // so don't emit them.
544 if (ItinList.empty())
545 continue;
546
Andrew Trick87255e32012-07-07 04:00:00 +0000547 OS << "\n";
548 OS << "static const llvm::InstrItinerary ";
Andrew Trick87255e32012-07-07 04:00:00 +0000549
550 // Begin processor itinerary table
Alexander Shaposhnikovd968f6f2017-07-05 20:14:54 +0000551 OS << ItinsDef->getName() << "[] = {\n";
Andrew Trick87255e32012-07-07 04:00:00 +0000552
553 // For each itinerary class in CodeGenSchedClass::Index order.
554 for (unsigned j = 0, M = ItinList.size(); j < M; ++j) {
555 InstrItinerary &Intinerary = ItinList[j];
556
557 // Emit Itinerary in the form of
558 // { firstStage, lastStage, firstCycle, lastCycle } // index
559 OS << " { " <<
560 Intinerary.NumMicroOps << ", " <<
561 Intinerary.FirstStage << ", " <<
562 Intinerary.LastStage << ", " <<
563 Intinerary.FirstOperandCycle << ", " <<
564 Intinerary.LastOperandCycle << " }" <<
565 ", // " << j << " " << SchedModels.getSchedClass(j).Name << "\n";
566 }
567 // End processor itinerary table
Benjamin Kramerb941aba2018-02-23 19:32:56 +0000568 OS << " { 0, uint16_t(~0U), uint16_t(~0U), uint16_t(~0U), uint16_t(~0U) }"
569 "// end marker\n";
Andrew Trick87255e32012-07-07 04:00:00 +0000570 OS << "};\n";
571 }
572}
573
Sylvestre Ledru35521e22012-07-23 08:51:15 +0000574// Emit either the value defined in the TableGen Record, or the default
Andrew Trick87255e32012-07-07 04:00:00 +0000575// value defined in the C++ header. The Record is null if the processor does not
576// define a model.
577void SubtargetEmitter::EmitProcessorProp(raw_ostream &OS, const Record *R,
Mehdi Amini32986ed2016-10-04 23:47:33 +0000578 StringRef Name, char Separator) {
Andrew Trick73d77362012-06-05 03:44:40 +0000579 OS << " ";
Andrew Trick87255e32012-07-07 04:00:00 +0000580 int V = R ? R->getValueAsInt(Name) : -1;
Andrew Trick73d77362012-06-05 03:44:40 +0000581 if (V >= 0)
582 OS << V << Separator << " // " << Name;
583 else
Andrew Trick87255e32012-07-07 04:00:00 +0000584 OS << "MCSchedModel::Default" << Name << Separator;
Andrew Trick73d77362012-06-05 03:44:40 +0000585 OS << '\n';
586}
587
Clement Courbet39911e22018-02-08 08:46:48 +0000588void SubtargetEmitter::EmitProcessorResourceSubUnits(
589 const CodeGenProcModel &ProcModel, raw_ostream &OS) {
590 OS << "\nstatic const unsigned " << ProcModel.ModelName
591 << "ProcResourceSubUnits[] = {\n"
592 << " 0, // Invalid\n";
593
594 for (unsigned i = 0, e = ProcModel.ProcResourceDefs.size(); i < e; ++i) {
595 Record *PRDef = ProcModel.ProcResourceDefs[i];
596 if (!PRDef->isSubClassOf("ProcResGroup"))
597 continue;
598 RecVec ResUnits = PRDef->getValueAsListOfDefs("Resources");
599 for (Record *RUDef : ResUnits) {
600 Record *const RU =
601 SchedModels.findProcResUnits(RUDef, ProcModel, PRDef->getLoc());
602 for (unsigned J = 0; J < RU->getValueAsInt("NumUnits"); ++J) {
603 OS << " " << ProcModel.getProcResourceIdx(RU) << ", ";
604 }
605 }
606 OS << " // " << PRDef->getName() << "\n";
607 }
608 OS << "};\n";
609}
610
Andrea Di Biagio378d75a2018-04-04 11:53:13 +0000611static void EmitRegisterFileInfo(const CodeGenProcModel &ProcModel,
612 unsigned NumRegisterFiles,
613 unsigned NumCostEntries, raw_ostream &OS) {
614 if (NumRegisterFiles)
615 OS << ProcModel.ModelName << "RegisterFiles,\n " << (1 + NumRegisterFiles);
616 else
617 OS << "nullptr,\n 0,\n ";
618
619 OS << ", // Number of register files.\n ";
620 if (NumCostEntries)
621 OS << ProcModel.ModelName << "RegisterCosts,\n ";
622 else
623 OS << "nullptr, \n";
624 OS << NumCostEntries << " // Number of register cost entries.\n";
625}
626
627unsigned
628SubtargetEmitter::EmitRegisterFileTables(const CodeGenProcModel &ProcModel,
629 raw_ostream &OS) {
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +0000630 if (llvm::all_of(ProcModel.RegisterFiles, [](const CodeGenRegisterFile &RF) {
631 return RF.hasDefaultCosts();
632 }))
Andrea Di Biagio378d75a2018-04-04 11:53:13 +0000633 return 0;
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +0000634
635 // Print the RegisterCost table first.
636 OS << "\n// {RegisterClassID, Register Cost}\n";
637 OS << "static const llvm::MCRegisterCostEntry " << ProcModel.ModelName
638 << "RegisterCosts"
639 << "[] = {\n";
640
641 for (const CodeGenRegisterFile &RF : ProcModel.RegisterFiles) {
642 // Skip register files with a default cost table.
643 if (RF.hasDefaultCosts())
644 continue;
645 // Add entries to the cost table.
646 for (const CodeGenRegisterCost &RC : RF.Costs) {
647 OS << " { ";
648 Record *Rec = RC.RCDef;
649 if (Rec->getValue("Namespace"))
650 OS << Rec->getValueAsString("Namespace") << "::";
651 OS << Rec->getName() << "RegClassID, " << RC.Cost << "},\n";
652 }
653 }
654 OS << "};\n";
655
656 // Now generate a table with register file info.
657 OS << "\n // {Name, #PhysRegs, #CostEntries, IndexToCostTbl}\n";
658 OS << "static const llvm::MCRegisterFileDesc " << ProcModel.ModelName
659 << "RegisterFiles"
660 << "[] = {\n"
661 << " { \"InvalidRegisterFile\", 0, 0, 0 },\n";
662 unsigned CostTblIndex = 0;
663
664 for (const CodeGenRegisterFile &RD : ProcModel.RegisterFiles) {
665 OS << " { ";
666 OS << '"' << RD.Name << '"' << ", " << RD.NumPhysRegs << ", ";
667 unsigned NumCostEntries = RD.Costs.size();
668 OS << NumCostEntries << ", " << CostTblIndex << "},\n";
669 CostTblIndex += NumCostEntries;
670 }
671 OS << "};\n";
672
Andrea Di Biagio378d75a2018-04-04 11:53:13 +0000673 return CostTblIndex;
674}
675
676void SubtargetEmitter::EmitExtraProcessorInfo(const CodeGenProcModel &ProcModel,
677 raw_ostream &OS) {
678 // Generate a table of register file descriptors (one entry per each user
679 // defined register file), and a table of register costs.
680 unsigned NumCostEntries = EmitRegisterFileTables(ProcModel, OS);
681
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +0000682 // Now generate a table for the extra processor info.
683 OS << "\nstatic const llvm::MCExtraProcessorInfo " << ProcModel.ModelName
Andrea Di Biagio378d75a2018-04-04 11:53:13 +0000684 << "ExtraInfo = {\n ";
685
686 // Add information related to the register files (i.e. where to find register
687 // file descriptors and register costs).
688 EmitRegisterFileInfo(ProcModel, ProcModel.RegisterFiles.size(),
689 NumCostEntries, OS);
690
691 OS << "};\n";
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +0000692}
693
Andrew Trick23f3c652012-09-17 22:18:45 +0000694void SubtargetEmitter::EmitProcessorResources(const CodeGenProcModel &ProcModel,
695 raw_ostream &OS) {
Clement Courbet39911e22018-02-08 08:46:48 +0000696 EmitProcessorResourceSubUnits(ProcModel, OS);
697
698 OS << "\n// {Name, NumUnits, SuperIdx, IsBuffered, SubUnitsIdxBegin}\n";
David Blaikiee6503d82018-02-08 19:57:05 +0000699 OS << "static const llvm::MCProcResourceDesc " << ProcModel.ModelName
700 << "ProcResources"
701 << "[] = {\n"
Andrea Di Biagio30e94022018-03-08 10:38:45 +0000702 << " {\"InvalidUnit\", 0, 0, 0, 0},\n";
Andrew Trick23f3c652012-09-17 22:18:45 +0000703
Clement Courbet39911e22018-02-08 08:46:48 +0000704 unsigned SubUnitsOffset = 1;
Andrew Trick23f3c652012-09-17 22:18:45 +0000705 for (unsigned i = 0, e = ProcModel.ProcResourceDefs.size(); i < e; ++i) {
706 Record *PRDef = ProcModel.ProcResourceDefs[i];
707
Craig Topper24064772014-04-15 07:20:03 +0000708 Record *SuperDef = nullptr;
Andrew Trick4e67cba2013-03-14 21:21:50 +0000709 unsigned SuperIdx = 0;
710 unsigned NumUnits = 0;
Clement Courbet39911e22018-02-08 08:46:48 +0000711 const unsigned SubUnitsBeginOffset = SubUnitsOffset;
Andrew Trick40c4f382013-06-15 04:50:06 +0000712 int BufferSize = PRDef->getValueAsInt("BufferSize");
Andrew Trick4e67cba2013-03-14 21:21:50 +0000713 if (PRDef->isSubClassOf("ProcResGroup")) {
714 RecVec ResUnits = PRDef->getValueAsListOfDefs("Resources");
Craig Topper29c55dcb2016-02-13 06:03:32 +0000715 for (Record *RU : ResUnits) {
716 NumUnits += RU->getValueAsInt("NumUnits");
Clement Courbet873aa112018-02-09 10:28:46 +0000717 SubUnitsOffset += RU->getValueAsInt("NumUnits");
Andrew Trick4e67cba2013-03-14 21:21:50 +0000718 }
719 }
720 else {
721 // Find the SuperIdx
722 if (PRDef->getValueInit("Super")->isComplete()) {
Evandro Menezes9dc54e22017-11-21 21:33:52 +0000723 SuperDef =
724 SchedModels.findProcResUnits(PRDef->getValueAsDef("Super"),
725 ProcModel, PRDef->getLoc());
Andrew Trick4e67cba2013-03-14 21:21:50 +0000726 SuperIdx = ProcModel.getProcResourceIdx(SuperDef);
727 }
Andrew Tricka5c747b2013-03-14 22:47:01 +0000728 NumUnits = PRDef->getValueAsInt("NumUnits");
Andrew Trick23f3c652012-09-17 22:18:45 +0000729 }
730 // Emit the ProcResourceDesc
Andrea Di Biagio30e94022018-03-08 10:38:45 +0000731 OS << " {\"" << PRDef->getName() << "\", ";
Andrew Trick23f3c652012-09-17 22:18:45 +0000732 if (PRDef->getName().size() < 15)
733 OS.indent(15 - PRDef->getName().size());
Clement Courbet39911e22018-02-08 08:46:48 +0000734 OS << NumUnits << ", " << SuperIdx << ", " << BufferSize << ", ";
735 if (SubUnitsBeginOffset != SubUnitsOffset) {
736 OS << ProcModel.ModelName << "ProcResourceSubUnits + "
737 << SubUnitsBeginOffset;
738 } else {
739 OS << "nullptr";
740 }
741 OS << "}, // #" << i+1;
Andrew Trick23f3c652012-09-17 22:18:45 +0000742 if (SuperDef)
743 OS << ", Super=" << SuperDef->getName();
744 OS << "\n";
745 }
746 OS << "};\n";
747}
748
Andrew Trick9ef08822012-09-17 22:18:48 +0000749// Find the WriteRes Record that defines processor resources for this
750// SchedWrite.
751Record *SubtargetEmitter::FindWriteResources(
Andrew Trick9257b8f2012-09-22 02:24:21 +0000752 const CodeGenSchedRW &SchedWrite, const CodeGenProcModel &ProcModel) {
Andrew Trick9ef08822012-09-17 22:18:48 +0000753
754 // Check if the SchedWrite is already subtarget-specific and directly
755 // specifies a set of processor resources.
Andrew Trick9257b8f2012-09-22 02:24:21 +0000756 if (SchedWrite.TheDef->isSubClassOf("SchedWriteRes"))
757 return SchedWrite.TheDef;
758
Craig Topper24064772014-04-15 07:20:03 +0000759 Record *AliasDef = nullptr;
Craig Topper29c55dcb2016-02-13 06:03:32 +0000760 for (Record *A : SchedWrite.Aliases) {
Andrew Trick9257b8f2012-09-22 02:24:21 +0000761 const CodeGenSchedRW &AliasRW =
Craig Topper29c55dcb2016-02-13 06:03:32 +0000762 SchedModels.getSchedRW(A->getValueAsDef("AliasRW"));
Andrew Trickda984b12012-10-03 23:06:28 +0000763 if (AliasRW.TheDef->getValueInit("SchedModel")->isComplete()) {
764 Record *ModelDef = AliasRW.TheDef->getValueAsDef("SchedModel");
765 if (&SchedModels.getProcModel(ModelDef) != &ProcModel)
766 continue;
767 }
Andrew Trick9257b8f2012-09-22 02:24:21 +0000768 if (AliasDef)
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000769 PrintFatalError(AliasRW.TheDef->getLoc(), "Multiple aliases "
Andrew Trick9257b8f2012-09-22 02:24:21 +0000770 "defined for processor " + ProcModel.ModelName +
771 " Ensure only one SchedAlias exists per RW.");
772 AliasDef = AliasRW.TheDef;
773 }
774 if (AliasDef && AliasDef->isSubClassOf("SchedWriteRes"))
775 return AliasDef;
Andrew Trick9ef08822012-09-17 22:18:48 +0000776
777 // Check this processor's list of write resources.
Craig Topper24064772014-04-15 07:20:03 +0000778 Record *ResDef = nullptr;
Craig Topper29c55dcb2016-02-13 06:03:32 +0000779 for (Record *WR : ProcModel.WriteResDefs) {
780 if (!WR->isSubClassOf("WriteRes"))
Andrew Trick9ef08822012-09-17 22:18:48 +0000781 continue;
Craig Topper29c55dcb2016-02-13 06:03:32 +0000782 if (AliasDef == WR->getValueAsDef("WriteType")
783 || SchedWrite.TheDef == WR->getValueAsDef("WriteType")) {
Andrew Trick9257b8f2012-09-22 02:24:21 +0000784 if (ResDef) {
Craig Topper29c55dcb2016-02-13 06:03:32 +0000785 PrintFatalError(WR->getLoc(), "Resources are defined for both "
Andrew Trick9257b8f2012-09-22 02:24:21 +0000786 "SchedWrite and its alias on processor " +
787 ProcModel.ModelName);
788 }
Craig Topper29c55dcb2016-02-13 06:03:32 +0000789 ResDef = WR;
Andrew Trick9257b8f2012-09-22 02:24:21 +0000790 }
Andrew Trick9ef08822012-09-17 22:18:48 +0000791 }
Andrew Trick9257b8f2012-09-22 02:24:21 +0000792 // TODO: If ProcModel has a base model (previous generation processor),
793 // then call FindWriteResources recursively with that model here.
794 if (!ResDef) {
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000795 PrintFatalError(ProcModel.ModelDef->getLoc(),
Craig Topper01ebd9b2017-10-26 20:49:36 +0000796 Twine("Processor does not define resources for ") +
797 SchedWrite.TheDef->getName());
Andrew Trick9257b8f2012-09-22 02:24:21 +0000798 }
799 return ResDef;
Andrew Trick9ef08822012-09-17 22:18:48 +0000800}
801
802/// Find the ReadAdvance record for the given SchedRead on this processor or
803/// return NULL.
Andrew Trick9257b8f2012-09-22 02:24:21 +0000804Record *SubtargetEmitter::FindReadAdvance(const CodeGenSchedRW &SchedRead,
Andrew Trick9ef08822012-09-17 22:18:48 +0000805 const CodeGenProcModel &ProcModel) {
806 // Check for SchedReads that directly specify a ReadAdvance.
Andrew Trick9257b8f2012-09-22 02:24:21 +0000807 if (SchedRead.TheDef->isSubClassOf("SchedReadAdvance"))
808 return SchedRead.TheDef;
809
810 // Check this processor's list of aliases for SchedRead.
Craig Topper24064772014-04-15 07:20:03 +0000811 Record *AliasDef = nullptr;
Craig Topper29c55dcb2016-02-13 06:03:32 +0000812 for (Record *A : SchedRead.Aliases) {
Andrew Trick9257b8f2012-09-22 02:24:21 +0000813 const CodeGenSchedRW &AliasRW =
Craig Topper29c55dcb2016-02-13 06:03:32 +0000814 SchedModels.getSchedRW(A->getValueAsDef("AliasRW"));
Andrew Trickda984b12012-10-03 23:06:28 +0000815 if (AliasRW.TheDef->getValueInit("SchedModel")->isComplete()) {
816 Record *ModelDef = AliasRW.TheDef->getValueAsDef("SchedModel");
817 if (&SchedModels.getProcModel(ModelDef) != &ProcModel)
818 continue;
819 }
Andrew Trick9257b8f2012-09-22 02:24:21 +0000820 if (AliasDef)
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000821 PrintFatalError(AliasRW.TheDef->getLoc(), "Multiple aliases "
Andrew Trick9257b8f2012-09-22 02:24:21 +0000822 "defined for processor " + ProcModel.ModelName +
823 " Ensure only one SchedAlias exists per RW.");
824 AliasDef = AliasRW.TheDef;
825 }
826 if (AliasDef && AliasDef->isSubClassOf("SchedReadAdvance"))
827 return AliasDef;
Andrew Trick9ef08822012-09-17 22:18:48 +0000828
829 // Check this processor's ReadAdvanceList.
Craig Topper24064772014-04-15 07:20:03 +0000830 Record *ResDef = nullptr;
Craig Topper29c55dcb2016-02-13 06:03:32 +0000831 for (Record *RA : ProcModel.ReadAdvanceDefs) {
832 if (!RA->isSubClassOf("ReadAdvance"))
Andrew Trick9ef08822012-09-17 22:18:48 +0000833 continue;
Craig Topper29c55dcb2016-02-13 06:03:32 +0000834 if (AliasDef == RA->getValueAsDef("ReadType")
835 || SchedRead.TheDef == RA->getValueAsDef("ReadType")) {
Andrew Trick9257b8f2012-09-22 02:24:21 +0000836 if (ResDef) {
Craig Topper29c55dcb2016-02-13 06:03:32 +0000837 PrintFatalError(RA->getLoc(), "Resources are defined for both "
Andrew Trick9257b8f2012-09-22 02:24:21 +0000838 "SchedRead and its alias on processor " +
839 ProcModel.ModelName);
840 }
Craig Topper29c55dcb2016-02-13 06:03:32 +0000841 ResDef = RA;
Andrew Trick9257b8f2012-09-22 02:24:21 +0000842 }
Andrew Trick9ef08822012-09-17 22:18:48 +0000843 }
Andrew Trick9257b8f2012-09-22 02:24:21 +0000844 // TODO: If ProcModel has a base model (previous generation processor),
845 // then call FindReadAdvance recursively with that model here.
846 if (!ResDef && SchedRead.TheDef->getName() != "ReadDefault") {
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000847 PrintFatalError(ProcModel.ModelDef->getLoc(),
Craig Topper01ebd9b2017-10-26 20:49:36 +0000848 Twine("Processor does not define resources for ") +
849 SchedRead.TheDef->getName());
Andrew Trick9ef08822012-09-17 22:18:48 +0000850 }
Andrew Trick9257b8f2012-09-22 02:24:21 +0000851 return ResDef;
Andrew Trick9ef08822012-09-17 22:18:48 +0000852}
853
Andrew Trick4e67cba2013-03-14 21:21:50 +0000854// Expand an explicit list of processor resources into a full list of implied
Andrew Tricka3801a32013-04-23 23:45:16 +0000855// resource groups and super resources that cover them.
Andrew Trick4e67cba2013-03-14 21:21:50 +0000856void SubtargetEmitter::ExpandProcResources(RecVec &PRVec,
857 std::vector<int64_t> &Cycles,
Andrew Tricka3801a32013-04-23 23:45:16 +0000858 const CodeGenProcModel &PM) {
Andrew Trick4e67cba2013-03-14 21:21:50 +0000859 // Default to 1 resource cycle.
860 Cycles.resize(PRVec.size(), 1);
861 for (unsigned i = 0, e = PRVec.size(); i != e; ++i) {
Andrew Tricka3801a32013-04-23 23:45:16 +0000862 Record *PRDef = PRVec[i];
Andrew Trick4e67cba2013-03-14 21:21:50 +0000863 RecVec SubResources;
Andrew Tricka3801a32013-04-23 23:45:16 +0000864 if (PRDef->isSubClassOf("ProcResGroup"))
865 SubResources = PRDef->getValueAsListOfDefs("Resources");
Andrew Trick4e67cba2013-03-14 21:21:50 +0000866 else {
Andrew Tricka3801a32013-04-23 23:45:16 +0000867 SubResources.push_back(PRDef);
Evandro Menezes9dc54e22017-11-21 21:33:52 +0000868 PRDef = SchedModels.findProcResUnits(PRDef, PM, PRDef->getLoc());
Andrew Tricka3801a32013-04-23 23:45:16 +0000869 for (Record *SubDef = PRDef;
870 SubDef->getValueInit("Super")->isComplete();) {
871 if (SubDef->isSubClassOf("ProcResGroup")) {
872 // Disallow this for simplicitly.
873 PrintFatalError(SubDef->getLoc(), "Processor resource group "
874 " cannot be a super resources.");
875 }
876 Record *SuperDef =
Evandro Menezes9dc54e22017-11-21 21:33:52 +0000877 SchedModels.findProcResUnits(SubDef->getValueAsDef("Super"), PM,
878 SubDef->getLoc());
Andrew Tricka3801a32013-04-23 23:45:16 +0000879 PRVec.push_back(SuperDef);
880 Cycles.push_back(Cycles[i]);
881 SubDef = SuperDef;
882 }
Andrew Trick4e67cba2013-03-14 21:21:50 +0000883 }
Craig Topper29c55dcb2016-02-13 06:03:32 +0000884 for (Record *PR : PM.ProcResourceDefs) {
885 if (PR == PRDef || !PR->isSubClassOf("ProcResGroup"))
Andrew Trick4e67cba2013-03-14 21:21:50 +0000886 continue;
Craig Topper29c55dcb2016-02-13 06:03:32 +0000887 RecVec SuperResources = PR->getValueAsListOfDefs("Resources");
Andrew Trick4e67cba2013-03-14 21:21:50 +0000888 RecIter SubI = SubResources.begin(), SubE = SubResources.end();
Andrew Trick6aa7a872013-04-23 23:45:11 +0000889 for( ; SubI != SubE; ++SubI) {
David Majnemer0d955d02016-08-11 22:21:41 +0000890 if (!is_contained(SuperResources, *SubI)) {
Andrew Trick4e67cba2013-03-14 21:21:50 +0000891 break;
Andrew Trick6aa7a872013-04-23 23:45:11 +0000892 }
Andrew Trick4e67cba2013-03-14 21:21:50 +0000893 }
894 if (SubI == SubE) {
Craig Topper29c55dcb2016-02-13 06:03:32 +0000895 PRVec.push_back(PR);
Andrew Trick4e67cba2013-03-14 21:21:50 +0000896 Cycles.push_back(Cycles[i]);
897 }
898 }
899 }
900}
901
Andrew Trick9ef08822012-09-17 22:18:48 +0000902// Generate the SchedClass table for this processor and update global
903// tables. Must be called for each processor in order.
904void SubtargetEmitter::GenSchedClassTables(const CodeGenProcModel &ProcModel,
905 SchedClassTables &SchedTables) {
906 SchedTables.ProcSchedClasses.resize(SchedTables.ProcSchedClasses.size() + 1);
907 if (!ProcModel.hasInstrSchedModel())
908 return;
909
910 std::vector<MCSchedClassDesc> &SCTab = SchedTables.ProcSchedClasses.back();
Joel Jones80372332017-06-28 00:06:40 +0000911 DEBUG(dbgs() << "\n+++ SCHED CLASSES (GenSchedClassTables) +++\n");
Craig Topper29c55dcb2016-02-13 06:03:32 +0000912 for (const CodeGenSchedClass &SC : SchedModels.schedClasses()) {
913 DEBUG(SC.dump(&SchedModels));
Andrew Trick7aba6be2012-10-03 23:06:25 +0000914
Andrew Trick9ef08822012-09-17 22:18:48 +0000915 SCTab.resize(SCTab.size() + 1);
916 MCSchedClassDesc &SCDesc = SCTab.back();
Andrew Trickab722bd2012-09-18 03:18:56 +0000917 // SCDesc.Name is guarded by NDEBUG
Andrew Trick9ef08822012-09-17 22:18:48 +0000918 SCDesc.NumMicroOps = 0;
919 SCDesc.BeginGroup = false;
920 SCDesc.EndGroup = false;
921 SCDesc.WriteProcResIdx = 0;
922 SCDesc.WriteLatencyIdx = 0;
923 SCDesc.ReadAdvanceIdx = 0;
924
925 // A Variant SchedClass has no resources of its own.
Andrew Tricke97978f2013-03-26 21:36:39 +0000926 bool HasVariants = false;
Javed Absar32e3cb72017-10-06 15:25:04 +0000927 for (const CodeGenSchedTransition &CGT :
928 make_range(SC.Transitions.begin(), SC.Transitions.end())) {
929 if (CGT.ProcIndices[0] == 0 ||
930 is_contained(CGT.ProcIndices, ProcModel.Index)) {
Andrew Tricke97978f2013-03-26 21:36:39 +0000931 HasVariants = true;
932 break;
933 }
934 }
935 if (HasVariants) {
Andrew Trick9ef08822012-09-17 22:18:48 +0000936 SCDesc.NumMicroOps = MCSchedClassDesc::VariantNumMicroOps;
937 continue;
938 }
939
940 // Determine if the SchedClass is actually reachable on this processor. If
941 // not don't try to locate the processor resources, it will fail.
942 // If ProcIndices contains 0, this class applies to all processors.
Craig Topper29c55dcb2016-02-13 06:03:32 +0000943 assert(!SC.ProcIndices.empty() && "expect at least one procidx");
944 if (SC.ProcIndices[0] != 0) {
David Majnemer42531262016-08-12 03:55:06 +0000945 if (!is_contained(SC.ProcIndices, ProcModel.Index))
Andrew Trick9ef08822012-09-17 22:18:48 +0000946 continue;
947 }
Craig Topper29c55dcb2016-02-13 06:03:32 +0000948 IdxVec Writes = SC.Writes;
949 IdxVec Reads = SC.Reads;
950 if (!SC.InstRWs.empty()) {
Sylvestre Ledru543f15b2018-03-17 17:30:08 +0000951 // This class has a default ReadWrite list which can be overridden by
Andrew Trick7aba6be2012-10-03 23:06:25 +0000952 // InstRW definitions.
Craig Topper24064772014-04-15 07:20:03 +0000953 Record *RWDef = nullptr;
Craig Topper29c55dcb2016-02-13 06:03:32 +0000954 for (Record *RW : SC.InstRWs) {
955 Record *RWModelDef = RW->getValueAsDef("SchedModel");
Andrew Trick9ef08822012-09-17 22:18:48 +0000956 if (&ProcModel == &SchedModels.getProcModel(RWModelDef)) {
Craig Topper29c55dcb2016-02-13 06:03:32 +0000957 RWDef = RW;
Andrew Trick9ef08822012-09-17 22:18:48 +0000958 break;
959 }
960 }
961 if (RWDef) {
Andrew Trickda984b12012-10-03 23:06:28 +0000962 Writes.clear();
963 Reads.clear();
Andrew Trick9ef08822012-09-17 22:18:48 +0000964 SchedModels.findRWs(RWDef->getValueAsListOfDefs("OperandReadWrites"),
965 Writes, Reads);
966 }
967 }
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000968 if (Writes.empty()) {
969 // Check this processor's itinerary class resources.
Craig Topper29c55dcb2016-02-13 06:03:32 +0000970 for (Record *I : ProcModel.ItinRWDefs) {
971 RecVec Matched = I->getValueAsListOfDefs("MatchedItinClasses");
David Majnemer0d955d02016-08-11 22:21:41 +0000972 if (is_contained(Matched, SC.ItinClassDef)) {
Craig Topper29c55dcb2016-02-13 06:03:32 +0000973 SchedModels.findRWs(I->getValueAsListOfDefs("OperandReadWrites"),
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000974 Writes, Reads);
975 break;
976 }
977 }
978 if (Writes.empty()) {
979 DEBUG(dbgs() << ProcModel.ModelName
Craig Topper29c55dcb2016-02-13 06:03:32 +0000980 << " does not have resources for class " << SC.Name << '\n');
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000981 }
982 }
Andrew Trick9ef08822012-09-17 22:18:48 +0000983 // Sum resources across all operand writes.
984 std::vector<MCWriteProcResEntry> WriteProcResources;
985 std::vector<MCWriteLatencyEntry> WriteLatencies;
Andrew Trickcfe222c2012-09-19 04:43:19 +0000986 std::vector<std::string> WriterNames;
Andrew Trick9ef08822012-09-17 22:18:48 +0000987 std::vector<MCReadAdvanceEntry> ReadAdvanceEntries;
Craig Topper29c55dcb2016-02-13 06:03:32 +0000988 for (unsigned W : Writes) {
Andrew Trick9ef08822012-09-17 22:18:48 +0000989 IdxVec WriteSeq;
Craig Topper29c55dcb2016-02-13 06:03:32 +0000990 SchedModels.expandRWSeqForProc(W, WriteSeq, /*IsRead=*/false,
Andrew Trickda984b12012-10-03 23:06:28 +0000991 ProcModel);
Andrew Trick9ef08822012-09-17 22:18:48 +0000992
993 // For each operand, create a latency entry.
994 MCWriteLatencyEntry WLEntry;
995 WLEntry.Cycles = 0;
Andrew Trickcfe222c2012-09-19 04:43:19 +0000996 unsigned WriteID = WriteSeq.back();
997 WriterNames.push_back(SchedModels.getSchedWrite(WriteID).Name);
998 // If this Write is not referenced by a ReadAdvance, don't distinguish it
999 // from other WriteLatency entries.
Andrew Trickbf8a28d2013-03-16 18:58:55 +00001000 if (!SchedModels.hasReadOfWrite(
1001 SchedModels.getSchedWrite(WriteID).TheDef)) {
Andrew Trickcfe222c2012-09-19 04:43:19 +00001002 WriteID = 0;
1003 }
1004 WLEntry.WriteResourceID = WriteID;
Andrew Trick9ef08822012-09-17 22:18:48 +00001005
Craig Topper29c55dcb2016-02-13 06:03:32 +00001006 for (unsigned WS : WriteSeq) {
Andrew Trick9ef08822012-09-17 22:18:48 +00001007
Andrew Trick9257b8f2012-09-22 02:24:21 +00001008 Record *WriteRes =
Craig Topper29c55dcb2016-02-13 06:03:32 +00001009 FindWriteResources(SchedModels.getSchedWrite(WS), ProcModel);
Andrew Trick9ef08822012-09-17 22:18:48 +00001010
1011 // Mark the parent class as invalid for unsupported write types.
1012 if (WriteRes->getValueAsBit("Unsupported")) {
1013 SCDesc.NumMicroOps = MCSchedClassDesc::InvalidNumMicroOps;
1014 break;
1015 }
1016 WLEntry.Cycles += WriteRes->getValueAsInt("Latency");
1017 SCDesc.NumMicroOps += WriteRes->getValueAsInt("NumMicroOps");
1018 SCDesc.BeginGroup |= WriteRes->getValueAsBit("BeginGroup");
1019 SCDesc.EndGroup |= WriteRes->getValueAsBit("EndGroup");
Javed Absar3d594372017-03-27 20:46:37 +00001020 SCDesc.BeginGroup |= WriteRes->getValueAsBit("SingleIssue");
1021 SCDesc.EndGroup |= WriteRes->getValueAsBit("SingleIssue");
Andrew Trick9ef08822012-09-17 22:18:48 +00001022
1023 // Create an entry for each ProcResource listed in WriteRes.
1024 RecVec PRVec = WriteRes->getValueAsListOfDefs("ProcResources");
1025 std::vector<int64_t> Cycles =
1026 WriteRes->getValueAsListOfInts("ResourceCycles");
Andrew Trick4e67cba2013-03-14 21:21:50 +00001027
1028 ExpandProcResources(PRVec, Cycles, ProcModel);
1029
Andrew Trick9ef08822012-09-17 22:18:48 +00001030 for (unsigned PRIdx = 0, PREnd = PRVec.size();
1031 PRIdx != PREnd; ++PRIdx) {
1032 MCWriteProcResEntry WPREntry;
1033 WPREntry.ProcResourceIdx = ProcModel.getProcResourceIdx(PRVec[PRIdx]);
1034 assert(WPREntry.ProcResourceIdx && "Bad ProcResourceIdx");
Andrew Trick4e67cba2013-03-14 21:21:50 +00001035 WPREntry.Cycles = Cycles[PRIdx];
Andrew Trick3821d9d2013-03-01 23:31:26 +00001036 // If this resource is already used in this sequence, add the current
1037 // entry's cycles so that the same resource appears to be used
1038 // serially, rather than multiple parallel uses. This is important for
1039 // in-order machine where the resource consumption is a hazard.
1040 unsigned WPRIdx = 0, WPREnd = WriteProcResources.size();
1041 for( ; WPRIdx != WPREnd; ++WPRIdx) {
1042 if (WriteProcResources[WPRIdx].ProcResourceIdx
1043 == WPREntry.ProcResourceIdx) {
1044 WriteProcResources[WPRIdx].Cycles += WPREntry.Cycles;
1045 break;
1046 }
1047 }
1048 if (WPRIdx == WPREnd)
1049 WriteProcResources.push_back(WPREntry);
Andrew Trick9ef08822012-09-17 22:18:48 +00001050 }
1051 }
1052 WriteLatencies.push_back(WLEntry);
1053 }
1054 // Create an entry for each operand Read in this SchedClass.
1055 // Entries must be sorted first by UseIdx then by WriteResourceID.
1056 for (unsigned UseIdx = 0, EndIdx = Reads.size();
1057 UseIdx != EndIdx; ++UseIdx) {
Andrew Trick9257b8f2012-09-22 02:24:21 +00001058 Record *ReadAdvance =
1059 FindReadAdvance(SchedModels.getSchedRead(Reads[UseIdx]), ProcModel);
Andrew Trick9ef08822012-09-17 22:18:48 +00001060 if (!ReadAdvance)
1061 continue;
1062
1063 // Mark the parent class as invalid for unsupported write types.
1064 if (ReadAdvance->getValueAsBit("Unsupported")) {
1065 SCDesc.NumMicroOps = MCSchedClassDesc::InvalidNumMicroOps;
1066 break;
1067 }
1068 RecVec ValidWrites = ReadAdvance->getValueAsListOfDefs("ValidWrites");
1069 IdxVec WriteIDs;
1070 if (ValidWrites.empty())
1071 WriteIDs.push_back(0);
1072 else {
Craig Topper29c55dcb2016-02-13 06:03:32 +00001073 for (Record *VW : ValidWrites) {
1074 WriteIDs.push_back(SchedModels.getSchedRWIdx(VW, /*IsRead=*/false));
Andrew Trick9ef08822012-09-17 22:18:48 +00001075 }
1076 }
1077 std::sort(WriteIDs.begin(), WriteIDs.end());
Craig Topper29c55dcb2016-02-13 06:03:32 +00001078 for(unsigned W : WriteIDs) {
Andrew Trick9ef08822012-09-17 22:18:48 +00001079 MCReadAdvanceEntry RAEntry;
1080 RAEntry.UseIdx = UseIdx;
Craig Topper29c55dcb2016-02-13 06:03:32 +00001081 RAEntry.WriteResourceID = W;
Andrew Trick9ef08822012-09-17 22:18:48 +00001082 RAEntry.Cycles = ReadAdvance->getValueAsInt("Cycles");
1083 ReadAdvanceEntries.push_back(RAEntry);
1084 }
1085 }
1086 if (SCDesc.NumMicroOps == MCSchedClassDesc::InvalidNumMicroOps) {
1087 WriteProcResources.clear();
1088 WriteLatencies.clear();
1089 ReadAdvanceEntries.clear();
1090 }
1091 // Add the information for this SchedClass to the global tables using basic
1092 // compression.
1093 //
1094 // WritePrecRes entries are sorted by ProcResIdx.
1095 std::sort(WriteProcResources.begin(), WriteProcResources.end(),
1096 LessWriteProcResources());
1097
1098 SCDesc.NumWriteProcResEntries = WriteProcResources.size();
1099 std::vector<MCWriteProcResEntry>::iterator WPRPos =
1100 std::search(SchedTables.WriteProcResources.begin(),
1101 SchedTables.WriteProcResources.end(),
1102 WriteProcResources.begin(), WriteProcResources.end());
1103 if (WPRPos != SchedTables.WriteProcResources.end())
1104 SCDesc.WriteProcResIdx = WPRPos - SchedTables.WriteProcResources.begin();
1105 else {
1106 SCDesc.WriteProcResIdx = SchedTables.WriteProcResources.size();
1107 SchedTables.WriteProcResources.insert(WPRPos, WriteProcResources.begin(),
1108 WriteProcResources.end());
1109 }
1110 // Latency entries must remain in operand order.
1111 SCDesc.NumWriteLatencyEntries = WriteLatencies.size();
1112 std::vector<MCWriteLatencyEntry>::iterator WLPos =
1113 std::search(SchedTables.WriteLatencies.begin(),
1114 SchedTables.WriteLatencies.end(),
1115 WriteLatencies.begin(), WriteLatencies.end());
Andrew Trickcfe222c2012-09-19 04:43:19 +00001116 if (WLPos != SchedTables.WriteLatencies.end()) {
1117 unsigned idx = WLPos - SchedTables.WriteLatencies.begin();
1118 SCDesc.WriteLatencyIdx = idx;
1119 for (unsigned i = 0, e = WriteLatencies.size(); i < e; ++i)
1120 if (SchedTables.WriterNames[idx + i].find(WriterNames[i]) ==
1121 std::string::npos) {
1122 SchedTables.WriterNames[idx + i] += std::string("_") + WriterNames[i];
1123 }
1124 }
Andrew Trick9ef08822012-09-17 22:18:48 +00001125 else {
1126 SCDesc.WriteLatencyIdx = SchedTables.WriteLatencies.size();
Andrew Trickcfe222c2012-09-19 04:43:19 +00001127 SchedTables.WriteLatencies.insert(SchedTables.WriteLatencies.end(),
1128 WriteLatencies.begin(),
1129 WriteLatencies.end());
1130 SchedTables.WriterNames.insert(SchedTables.WriterNames.end(),
1131 WriterNames.begin(), WriterNames.end());
Andrew Trick9ef08822012-09-17 22:18:48 +00001132 }
1133 // ReadAdvanceEntries must remain in operand order.
1134 SCDesc.NumReadAdvanceEntries = ReadAdvanceEntries.size();
1135 std::vector<MCReadAdvanceEntry>::iterator RAPos =
1136 std::search(SchedTables.ReadAdvanceEntries.begin(),
1137 SchedTables.ReadAdvanceEntries.end(),
1138 ReadAdvanceEntries.begin(), ReadAdvanceEntries.end());
1139 if (RAPos != SchedTables.ReadAdvanceEntries.end())
1140 SCDesc.ReadAdvanceIdx = RAPos - SchedTables.ReadAdvanceEntries.begin();
1141 else {
1142 SCDesc.ReadAdvanceIdx = SchedTables.ReadAdvanceEntries.size();
1143 SchedTables.ReadAdvanceEntries.insert(RAPos, ReadAdvanceEntries.begin(),
1144 ReadAdvanceEntries.end());
1145 }
1146 }
1147}
1148
Andrew Tricka72fca62012-09-17 22:18:50 +00001149// Emit SchedClass tables for all processors and associated global tables.
1150void SubtargetEmitter::EmitSchedClassTables(SchedClassTables &SchedTables,
1151 raw_ostream &OS) {
1152 // Emit global WriteProcResTable.
1153 OS << "\n// {ProcResourceIdx, Cycles}\n"
1154 << "extern const llvm::MCWriteProcResEntry "
1155 << Target << "WriteProcResTable[] = {\n"
1156 << " { 0, 0}, // Invalid\n";
1157 for (unsigned WPRIdx = 1, WPREnd = SchedTables.WriteProcResources.size();
1158 WPRIdx != WPREnd; ++WPRIdx) {
1159 MCWriteProcResEntry &WPREntry = SchedTables.WriteProcResources[WPRIdx];
1160 OS << " {" << format("%2d", WPREntry.ProcResourceIdx) << ", "
1161 << format("%2d", WPREntry.Cycles) << "}";
1162 if (WPRIdx + 1 < WPREnd)
1163 OS << ',';
1164 OS << " // #" << WPRIdx << '\n';
1165 }
1166 OS << "}; // " << Target << "WriteProcResTable\n";
1167
1168 // Emit global WriteLatencyTable.
1169 OS << "\n// {Cycles, WriteResourceID}\n"
1170 << "extern const llvm::MCWriteLatencyEntry "
1171 << Target << "WriteLatencyTable[] = {\n"
1172 << " { 0, 0}, // Invalid\n";
1173 for (unsigned WLIdx = 1, WLEnd = SchedTables.WriteLatencies.size();
1174 WLIdx != WLEnd; ++WLIdx) {
1175 MCWriteLatencyEntry &WLEntry = SchedTables.WriteLatencies[WLIdx];
1176 OS << " {" << format("%2d", WLEntry.Cycles) << ", "
1177 << format("%2d", WLEntry.WriteResourceID) << "}";
1178 if (WLIdx + 1 < WLEnd)
1179 OS << ',';
Andrew Trickcfe222c2012-09-19 04:43:19 +00001180 OS << " // #" << WLIdx << " " << SchedTables.WriterNames[WLIdx] << '\n';
Andrew Tricka72fca62012-09-17 22:18:50 +00001181 }
1182 OS << "}; // " << Target << "WriteLatencyTable\n";
1183
1184 // Emit global ReadAdvanceTable.
1185 OS << "\n// {UseIdx, WriteResourceID, Cycles}\n"
1186 << "extern const llvm::MCReadAdvanceEntry "
1187 << Target << "ReadAdvanceTable[] = {\n"
1188 << " {0, 0, 0}, // Invalid\n";
1189 for (unsigned RAIdx = 1, RAEnd = SchedTables.ReadAdvanceEntries.size();
1190 RAIdx != RAEnd; ++RAIdx) {
1191 MCReadAdvanceEntry &RAEntry = SchedTables.ReadAdvanceEntries[RAIdx];
1192 OS << " {" << RAEntry.UseIdx << ", "
1193 << format("%2d", RAEntry.WriteResourceID) << ", "
1194 << format("%2d", RAEntry.Cycles) << "}";
1195 if (RAIdx + 1 < RAEnd)
1196 OS << ',';
1197 OS << " // #" << RAIdx << '\n';
1198 }
1199 OS << "}; // " << Target << "ReadAdvanceTable\n";
1200
1201 // Emit a SchedClass table for each processor.
1202 for (CodeGenSchedModels::ProcIter PI = SchedModels.procModelBegin(),
1203 PE = SchedModels.procModelEnd(); PI != PE; ++PI) {
1204 if (!PI->hasInstrSchedModel())
1205 continue;
1206
1207 std::vector<MCSchedClassDesc> &SCTab =
Rafael Espindola72961392012-11-02 20:57:36 +00001208 SchedTables.ProcSchedClasses[1 + (PI - SchedModels.procModelBegin())];
Andrew Tricka72fca62012-09-17 22:18:50 +00001209
1210 OS << "\n// {Name, NumMicroOps, BeginGroup, EndGroup,"
1211 << " WriteProcResIdx,#, WriteLatencyIdx,#, ReadAdvanceIdx,#}\n";
1212 OS << "static const llvm::MCSchedClassDesc "
1213 << PI->ModelName << "SchedClasses[] = {\n";
1214
1215 // The first class is always invalid. We no way to distinguish it except by
1216 // name and position.
Andrew Trickbf8a28d2013-03-16 18:58:55 +00001217 assert(SchedModels.getSchedClass(0).Name == "NoInstrModel"
Andrew Tricka72fca62012-09-17 22:18:50 +00001218 && "invalid class not first");
1219 OS << " {DBGFIELD(\"InvalidSchedClass\") "
1220 << MCSchedClassDesc::InvalidNumMicroOps
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001221 << ", false, false, 0, 0, 0, 0, 0, 0},\n";
Andrew Tricka72fca62012-09-17 22:18:50 +00001222
1223 for (unsigned SCIdx = 1, SCEnd = SCTab.size(); SCIdx != SCEnd; ++SCIdx) {
1224 MCSchedClassDesc &MCDesc = SCTab[SCIdx];
1225 const CodeGenSchedClass &SchedClass = SchedModels.getSchedClass(SCIdx);
1226 OS << " {DBGFIELD(\"" << SchedClass.Name << "\") ";
1227 if (SchedClass.Name.size() < 18)
1228 OS.indent(18 - SchedClass.Name.size());
1229 OS << MCDesc.NumMicroOps
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001230 << ", " << ( MCDesc.BeginGroup ? "true" : "false" )
1231 << ", " << ( MCDesc.EndGroup ? "true" : "false" )
Andrew Tricka72fca62012-09-17 22:18:50 +00001232 << ", " << format("%2d", MCDesc.WriteProcResIdx)
1233 << ", " << MCDesc.NumWriteProcResEntries
1234 << ", " << format("%2d", MCDesc.WriteLatencyIdx)
1235 << ", " << MCDesc.NumWriteLatencyEntries
1236 << ", " << format("%2d", MCDesc.ReadAdvanceIdx)
Craig Topperdf1285b2017-10-24 15:50:53 +00001237 << ", " << MCDesc.NumReadAdvanceEntries
1238 << "}, // #" << SCIdx << '\n';
Andrew Tricka72fca62012-09-17 22:18:50 +00001239 }
1240 OS << "}; // " << PI->ModelName << "SchedClasses\n";
1241 }
1242}
1243
Andrew Trick87255e32012-07-07 04:00:00 +00001244void SubtargetEmitter::EmitProcessorModels(raw_ostream &OS) {
1245 // For each processor model.
Craig Topper29c55dcb2016-02-13 06:03:32 +00001246 for (const CodeGenProcModel &PM : SchedModels.procModels()) {
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +00001247 // Emit extra processor info if available.
1248 if (PM.hasExtraProcessorInfo())
1249 EmitExtraProcessorInfo(PM, OS);
Andrew Trick23f3c652012-09-17 22:18:45 +00001250 // Emit processor resource table.
Craig Topper29c55dcb2016-02-13 06:03:32 +00001251 if (PM.hasInstrSchedModel())
1252 EmitProcessorResources(PM, OS);
1253 else if(!PM.ProcResourceDefs.empty())
1254 PrintFatalError(PM.ModelDef->getLoc(), "SchedMachineModel defines "
Andrew Trick9ef08822012-09-17 22:18:48 +00001255 "ProcResources without defining WriteRes SchedWriteRes");
Andrew Trick23f3c652012-09-17 22:18:45 +00001256
Andrew Trick73d77362012-06-05 03:44:40 +00001257 // Begin processor itinerary properties
1258 OS << "\n";
Craig Topper29c55dcb2016-02-13 06:03:32 +00001259 OS << "static const llvm::MCSchedModel " << PM.ModelName << " = {\n";
1260 EmitProcessorProp(OS, PM.ModelDef, "IssueWidth", ',');
1261 EmitProcessorProp(OS, PM.ModelDef, "MicroOpBufferSize", ',');
1262 EmitProcessorProp(OS, PM.ModelDef, "LoopMicroOpBufferSize", ',');
1263 EmitProcessorProp(OS, PM.ModelDef, "LoadLatency", ',');
1264 EmitProcessorProp(OS, PM.ModelDef, "HighLatency", ',');
1265 EmitProcessorProp(OS, PM.ModelDef, "MispredictPenalty", ',');
Andrew Trickb6854d82013-09-25 18:14:12 +00001266
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001267 bool PostRAScheduler =
1268 (PM.ModelDef ? PM.ModelDef->getValueAsBit("PostRAScheduler") : false);
Sanjay Patela2f658d2014-07-15 22:39:58 +00001269
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001270 OS << " " << (PostRAScheduler ? "true" : "false") << ", // "
1271 << "PostRAScheduler\n";
1272
1273 bool CompleteModel =
1274 (PM.ModelDef ? PM.ModelDef->getValueAsBit("CompleteModel") : false);
1275
1276 OS << " " << (CompleteModel ? "true" : "false") << ", // "
1277 << "CompleteModel\n";
Andrew Trickb6854d82013-09-25 18:14:12 +00001278
Craig Topper29c55dcb2016-02-13 06:03:32 +00001279 OS << " " << PM.Index << ", // Processor ID\n";
1280 if (PM.hasInstrSchedModel())
1281 OS << " " << PM.ModelName << "ProcResources" << ",\n"
1282 << " " << PM.ModelName << "SchedClasses" << ",\n"
1283 << " " << PM.ProcResourceDefs.size()+1 << ",\n"
Andrew Trickab722bd2012-09-18 03:18:56 +00001284 << " " << (SchedModels.schedClassEnd()
1285 - SchedModels.schedClassBegin()) << ",\n";
1286 else
Hans Wennborg083ca9b2015-10-06 23:24:35 +00001287 OS << " nullptr, nullptr, 0, 0,"
1288 << " // No instruction-level machine model.\n";
Craig Topper29c55dcb2016-02-13 06:03:32 +00001289 if (PM.hasItineraries())
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +00001290 OS << " " << PM.ItinsDef->getName() << ",\n";
Andrew Trick9c302672012-06-22 03:58:51 +00001291 else
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +00001292 OS << " nullptr, // No Itinerary\n";
1293 if (PM.hasExtraProcessorInfo())
1294 OS << " &" << PM.ModelName << "ExtraInfo\n";
1295 else
1296 OS << " nullptr // No extra processor descriptor\n";
Craig Topper194cb742017-10-24 15:50:55 +00001297 OS << "};\n";
Jim Laskey86f002c2005-10-27 19:47:21 +00001298 }
Jim Laskey3763a502005-10-31 17:16:01 +00001299}
1300
1301//
1302// EmitProcessorLookup - generate cpu name to itinerary lookup table.
1303//
Daniel Dunbar38a22bf2009-07-03 00:10:29 +00001304void SubtargetEmitter::EmitProcessorLookup(raw_ostream &OS) {
Jim Laskey3763a502005-10-31 17:16:01 +00001305 // Gather and sort processor information
1306 std::vector<Record*> ProcessorList =
1307 Records.getAllDerivedDefinitions("Processor");
Duraid Madina018da4f2005-12-30 14:56:37 +00001308 std::sort(ProcessorList.begin(), ProcessorList.end(), LessRecordFieldName());
Jim Laskey3763a502005-10-31 17:16:01 +00001309
1310 // Begin processor table
1311 OS << "\n";
1312 OS << "// Sorted (by key) array of itineraries for CPU subtype.\n"
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00001313 << "extern const llvm::SubtargetInfoKV "
Andrew Trick87255e32012-07-07 04:00:00 +00001314 << Target << "ProcSchedKV[] = {\n";
Andrew Trickdb6ed642011-04-01 01:56:55 +00001315
Jim Laskey3763a502005-10-31 17:16:01 +00001316 // For each processor
Craig Topperdf1285b2017-10-24 15:50:53 +00001317 for (Record *Processor : ProcessorList) {
Craig Topperbcd3c372017-05-31 21:12:46 +00001318 StringRef Name = Processor->getValueAsString("Name");
Andrew Trick87255e32012-07-07 04:00:00 +00001319 const std::string &ProcModelName =
Andrew Trick76686492012-09-15 00:19:57 +00001320 SchedModels.getModelForProc(Processor).ModelName;
Andrew Trickdb6ed642011-04-01 01:56:55 +00001321
Jim Laskey3763a502005-10-31 17:16:01 +00001322 // Emit as { "cpu", procinit },
Craig Topperdf1285b2017-10-24 15:50:53 +00001323 OS << " { \"" << Name << "\", (const void *)&" << ProcModelName << " },\n";
Jim Laskey3763a502005-10-31 17:16:01 +00001324 }
Andrew Trickdb6ed642011-04-01 01:56:55 +00001325
Jim Laskey3763a502005-10-31 17:16:01 +00001326 // End processor table
1327 OS << "};\n";
Jim Laskey86f002c2005-10-27 19:47:21 +00001328}
1329
1330//
Andrew Trick87255e32012-07-07 04:00:00 +00001331// EmitSchedModel - Emits all scheduling model tables, folding common patterns.
Jim Laskey86f002c2005-10-27 19:47:21 +00001332//
Andrew Trick87255e32012-07-07 04:00:00 +00001333void SubtargetEmitter::EmitSchedModel(raw_ostream &OS) {
Andrew Trick23f3c652012-09-17 22:18:45 +00001334 OS << "#ifdef DBGFIELD\n"
1335 << "#error \"<target>GenSubtargetInfo.inc requires a DBGFIELD macro\"\n"
1336 << "#endif\n"
Aaron Ballman615eb472017-10-15 14:32:27 +00001337 << "#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)\n"
Andrew Trick23f3c652012-09-17 22:18:45 +00001338 << "#define DBGFIELD(x) x,\n"
1339 << "#else\n"
1340 << "#define DBGFIELD(x)\n"
1341 << "#endif\n";
1342
Andrew Trickbf8a28d2013-03-16 18:58:55 +00001343 if (SchedModels.hasItineraries()) {
Eugene Zelenko2bc2f332016-12-09 22:06:55 +00001344 std::vector<std::vector<InstrItinerary>> ProcItinLists;
Jim Laskey802748c2005-11-01 20:06:59 +00001345 // Emit the stage data
Andrew Trick87255e32012-07-07 04:00:00 +00001346 EmitStageAndOperandCycleData(OS, ProcItinLists);
1347 EmitItineraries(OS, ProcItinLists);
Jim Laskey802748c2005-11-01 20:06:59 +00001348 }
Andrew Tricka72fca62012-09-17 22:18:50 +00001349 OS << "\n// ===============================================================\n"
1350 << "// Data tables for the new per-operand machine model.\n";
Andrew Trick23f3c652012-09-17 22:18:45 +00001351
Andrew Trick9ef08822012-09-17 22:18:48 +00001352 SchedClassTables SchedTables;
Craig Topper29c55dcb2016-02-13 06:03:32 +00001353 for (const CodeGenProcModel &ProcModel : SchedModels.procModels()) {
1354 GenSchedClassTables(ProcModel, SchedTables);
Andrew Trick9ef08822012-09-17 22:18:48 +00001355 }
Andrew Tricka72fca62012-09-17 22:18:50 +00001356 EmitSchedClassTables(SchedTables, OS);
1357
1358 // Emit the processor machine model
1359 EmitProcessorModels(OS);
1360 // Emit the processor lookup data
1361 EmitProcessorLookup(OS);
Andrew Trick9ef08822012-09-17 22:18:48 +00001362
Craig Topper194cb742017-10-24 15:50:55 +00001363 OS << "\n#undef DBGFIELD";
Jim Laskey86f002c2005-10-27 19:47:21 +00001364}
1365
Benjamin Kramerc321e532016-06-08 19:09:22 +00001366void SubtargetEmitter::EmitSchedModelHelpers(const std::string &ClassName,
Andrew Trickc6c88152012-09-18 03:41:43 +00001367 raw_ostream &OS) {
1368 OS << "unsigned " << ClassName
1369 << "\n::resolveSchedClass(unsigned SchedClass, const MachineInstr *MI,"
1370 << " const TargetSchedModel *SchedModel) const {\n";
1371
1372 std::vector<Record*> Prologs = Records.getAllDerivedDefinitions("PredicateProlog");
1373 std::sort(Prologs.begin(), Prologs.end(), LessRecord());
Craig Topper29c55dcb2016-02-13 06:03:32 +00001374 for (Record *P : Prologs) {
1375 OS << P->getValueAsString("Code") << '\n';
Andrew Trickc6c88152012-09-18 03:41:43 +00001376 }
1377 IdxVec VariantClasses;
Craig Topper29c55dcb2016-02-13 06:03:32 +00001378 for (const CodeGenSchedClass &SC : SchedModels.schedClasses()) {
1379 if (SC.Transitions.empty())
Andrew Trickc6c88152012-09-18 03:41:43 +00001380 continue;
Craig Topper29c55dcb2016-02-13 06:03:32 +00001381 VariantClasses.push_back(SC.Index);
Andrew Trickc6c88152012-09-18 03:41:43 +00001382 }
1383 if (!VariantClasses.empty()) {
1384 OS << " switch (SchedClass) {\n";
Craig Topper29c55dcb2016-02-13 06:03:32 +00001385 for (unsigned VC : VariantClasses) {
1386 const CodeGenSchedClass &SC = SchedModels.getSchedClass(VC);
1387 OS << " case " << VC << ": // " << SC.Name << '\n';
Andrew Trickc6c88152012-09-18 03:41:43 +00001388 IdxVec ProcIndices;
Craig Topper29c55dcb2016-02-13 06:03:32 +00001389 for (const CodeGenSchedTransition &T : SC.Transitions) {
Andrew Trickc6c88152012-09-18 03:41:43 +00001390 IdxVec PI;
Craig Topper29c55dcb2016-02-13 06:03:32 +00001391 std::set_union(T.ProcIndices.begin(), T.ProcIndices.end(),
Andrew Trickc6c88152012-09-18 03:41:43 +00001392 ProcIndices.begin(), ProcIndices.end(),
1393 std::back_inserter(PI));
1394 ProcIndices.swap(PI);
1395 }
Craig Topper29c55dcb2016-02-13 06:03:32 +00001396 for (unsigned PI : ProcIndices) {
Andrew Trickc6c88152012-09-18 03:41:43 +00001397 OS << " ";
Craig Topper29c55dcb2016-02-13 06:03:32 +00001398 if (PI != 0)
1399 OS << "if (SchedModel->getProcessorID() == " << PI << ") ";
1400 OS << "{ // " << (SchedModels.procModelBegin() + PI)->ModelName
Andrew Trickc6c88152012-09-18 03:41:43 +00001401 << '\n';
Craig Topper29c55dcb2016-02-13 06:03:32 +00001402 for (const CodeGenSchedTransition &T : SC.Transitions) {
1403 if (PI != 0 && !std::count(T.ProcIndices.begin(),
1404 T.ProcIndices.end(), PI)) {
Andrew Trickc6c88152012-09-18 03:41:43 +00001405 continue;
1406 }
Arnold Schwaighofer218f6d82013-06-05 14:06:50 +00001407 OS << " if (";
Craig Topper29c55dcb2016-02-13 06:03:32 +00001408 for (RecIter RI = T.PredTerm.begin(), RE = T.PredTerm.end();
Andrew Trickc6c88152012-09-18 03:41:43 +00001409 RI != RE; ++RI) {
Craig Topper29c55dcb2016-02-13 06:03:32 +00001410 if (RI != T.PredTerm.begin())
Andrew Trickc6c88152012-09-18 03:41:43 +00001411 OS << "\n && ";
1412 OS << "(" << (*RI)->getValueAsString("Predicate") << ")";
1413 }
1414 OS << ")\n"
Craig Topper29c55dcb2016-02-13 06:03:32 +00001415 << " return " << T.ToClassIdx << "; // "
1416 << SchedModels.getSchedClass(T.ToClassIdx).Name << '\n';
Andrew Trickc6c88152012-09-18 03:41:43 +00001417 }
1418 OS << " }\n";
Craig Topper29c55dcb2016-02-13 06:03:32 +00001419 if (PI == 0)
Andrew Trickc6c88152012-09-18 03:41:43 +00001420 break;
1421 }
Andrew Trickbf8a28d2013-03-16 18:58:55 +00001422 if (SC.isInferred())
1423 OS << " return " << SC.Index << ";\n";
Andrew Trickc6c88152012-09-18 03:41:43 +00001424 OS << " break;\n";
1425 }
1426 OS << " };\n";
1427 }
1428 OS << " report_fatal_error(\"Expected a variant SchedClass\");\n"
1429 << "} // " << ClassName << "::resolveSchedClass\n";
1430}
1431
Krzysztof Parzyszek788e7682017-09-14 20:44:20 +00001432void SubtargetEmitter::EmitHwModeCheck(const std::string &ClassName,
1433 raw_ostream &OS) {
1434 const CodeGenHwModes &CGH = TGT.getHwModes();
1435 assert(CGH.getNumModeIds() > 0);
1436 if (CGH.getNumModeIds() == 1)
1437 return;
1438
1439 OS << "unsigned " << ClassName << "::getHwMode() const {\n";
1440 for (unsigned M = 1, NumModes = CGH.getNumModeIds(); M != NumModes; ++M) {
1441 const HwMode &HM = CGH.getMode(M);
1442 OS << " if (checkFeatures(\"" << HM.Features
1443 << "\")) return " << M << ";\n";
1444 }
1445 OS << " return 0;\n}\n";
1446}
1447
Jim Laskey86f002c2005-10-27 19:47:21 +00001448//
Jim Laskeya2b52352005-10-26 17:30:34 +00001449// ParseFeaturesFunction - Produces a subtarget specific function for parsing
1450// the subtarget features string.
1451//
Evan Cheng54b68e32011-07-01 20:45:01 +00001452void SubtargetEmitter::ParseFeaturesFunction(raw_ostream &OS,
1453 unsigned NumFeatures,
1454 unsigned NumProcs) {
Jim Laskeydffe5972005-10-28 21:47:29 +00001455 std::vector<Record*> Features =
1456 Records.getAllDerivedDefinitions("SubtargetFeature");
Duraid Madina018da4f2005-12-30 14:56:37 +00001457 std::sort(Features.begin(), Features.end(), LessRecord());
Jim Laskeya2b52352005-10-26 17:30:34 +00001458
Andrew Trickdb6ed642011-04-01 01:56:55 +00001459 OS << "// ParseSubtargetFeatures - Parses features string setting specified\n"
1460 << "// subtarget options.\n"
Evan Chengfe6e4052011-06-30 01:53:36 +00001461 << "void llvm::";
Jim Laskeya2b52352005-10-26 17:30:34 +00001462 OS << Target;
Evan Cheng1a72add62011-07-07 07:07:08 +00001463 OS << "Subtarget::ParseSubtargetFeatures(StringRef CPU, StringRef FS) {\n"
David Greenefb652a72010-01-05 17:47:41 +00001464 << " DEBUG(dbgs() << \"\\nFeatures:\" << FS);\n"
Hal Finkel060f5d22012-06-12 04:21:36 +00001465 << " DEBUG(dbgs() << \"\\nCPU:\" << CPU << \"\\n\\n\");\n";
Evan Cheng54b68e32011-07-01 20:45:01 +00001466
1467 if (Features.empty()) {
1468 OS << "}\n";
1469 return;
1470 }
1471
Andrew Trickba7b9212012-09-18 05:33:15 +00001472 OS << " InitMCProcessorInfo(CPU, FS);\n"
Michael Kupersteindb0712f2015-05-26 10:47:10 +00001473 << " const FeatureBitset& Bits = getFeatureBits();\n";
Bill Wendlinge6182262007-05-04 20:38:40 +00001474
Craig Topper29c55dcb2016-02-13 06:03:32 +00001475 for (Record *R : Features) {
Jim Laskeydffe5972005-10-28 21:47:29 +00001476 // Next record
Craig Topperbcd3c372017-05-31 21:12:46 +00001477 StringRef Instance = R->getName();
1478 StringRef Value = R->getValueAsString("Value");
1479 StringRef Attribute = R->getValueAsString("Attribute");
Evan Chengd98701c2006-01-27 08:09:42 +00001480
Dale Johannesen6ca3ccf2008-02-14 23:35:16 +00001481 if (Value=="true" || Value=="false")
Michael Kupersteindb0712f2015-05-26 10:47:10 +00001482 OS << " if (Bits[" << Target << "::"
1483 << Instance << "]) "
Dale Johannesen6ca3ccf2008-02-14 23:35:16 +00001484 << Attribute << " = " << Value << ";\n";
1485 else
Michael Kupersteindb0712f2015-05-26 10:47:10 +00001486 OS << " if (Bits[" << Target << "::"
1487 << Instance << "] && "
Evan Cheng54b68e32011-07-01 20:45:01 +00001488 << Attribute << " < " << Value << ") "
1489 << Attribute << " = " << Value << ";\n";
Jim Laskey802748c2005-11-01 20:06:59 +00001490 }
Anton Korobeynikov08bf4c02009-05-23 19:50:50 +00001491
Evan Chengfe6e4052011-06-30 01:53:36 +00001492 OS << "}\n";
Jim Laskeya2b52352005-10-26 17:30:34 +00001493}
1494
Anton Korobeynikov08bf4c02009-05-23 19:50:50 +00001495//
Jim Laskeycfda85a2005-10-21 19:00:04 +00001496// SubtargetEmitter::run - Main subtarget enumeration emitter.
1497//
Daniel Dunbar38a22bf2009-07-03 00:10:29 +00001498void SubtargetEmitter::run(raw_ostream &OS) {
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +00001499 emitSourceFileHeader("Subtarget Enumeration Source Fragment", OS);
Jim Laskeycfda85a2005-10-21 19:00:04 +00001500
Evan Cheng4d1ca962011-07-08 01:53:10 +00001501 OS << "\n#ifdef GET_SUBTARGETINFO_ENUM\n";
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001502 OS << "#undef GET_SUBTARGETINFO_ENUM\n\n";
Evan Cheng4d1ca962011-07-08 01:53:10 +00001503
1504 OS << "namespace llvm {\n";
Craig Topper094bbca2016-02-14 05:22:01 +00001505 Enumeration(OS);
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001506 OS << "} // end namespace llvm\n\n";
Evan Cheng4d1ca962011-07-08 01:53:10 +00001507 OS << "#endif // GET_SUBTARGETINFO_ENUM\n\n";
1508
Evan Cheng54b68e32011-07-01 20:45:01 +00001509 OS << "\n#ifdef GET_SUBTARGETINFO_MC_DESC\n";
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001510 OS << "#undef GET_SUBTARGETINFO_MC_DESC\n\n";
Anton Korobeynikov7d62e332010-04-18 20:31:01 +00001511
Evan Cheng54b68e32011-07-01 20:45:01 +00001512 OS << "namespace llvm {\n";
Evan Chengbc153d42011-07-14 20:59:42 +00001513#if 0
1514 OS << "namespace {\n";
1515#endif
Evan Cheng54b68e32011-07-01 20:45:01 +00001516 unsigned NumFeatures = FeatureKeyValues(OS);
Evan Chengbc153d42011-07-14 20:59:42 +00001517 OS << "\n";
Evan Cheng54b68e32011-07-01 20:45:01 +00001518 unsigned NumProcs = CPUKeyValues(OS);
Evan Chengbc153d42011-07-14 20:59:42 +00001519 OS << "\n";
Andrew Trick87255e32012-07-07 04:00:00 +00001520 EmitSchedModel(OS);
Evan Chengbc153d42011-07-14 20:59:42 +00001521 OS << "\n";
1522#if 0
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001523 OS << "} // end anonymous namespace\n\n";
Evan Chengbc153d42011-07-14 20:59:42 +00001524#endif
Evan Cheng54b68e32011-07-01 20:45:01 +00001525
1526 // MCInstrInfo initialization routine.
Craig Topper194cb742017-10-24 15:50:55 +00001527 OS << "\nstatic inline MCSubtargetInfo *create" << Target
Duncan P. N. Exon Smith754e21f2015-07-10 22:43:42 +00001528 << "MCSubtargetInfoImpl("
Daniel Sanders50f17232015-09-15 16:17:27 +00001529 << "const Triple &TT, StringRef CPU, StringRef FS) {\n";
Duncan P. N. Exon Smith754e21f2015-07-10 22:43:42 +00001530 OS << " return new MCSubtargetInfo(TT, CPU, FS, ";
Evan Cheng54b68e32011-07-01 20:45:01 +00001531 if (NumFeatures)
1532 OS << Target << "FeatureKV, ";
1533 else
Eric Christopherdc5072d2014-05-06 20:23:04 +00001534 OS << "None, ";
Evan Cheng54b68e32011-07-01 20:45:01 +00001535 if (NumProcs)
1536 OS << Target << "SubTypeKV, ";
1537 else
Eric Christopherdc5072d2014-05-06 20:23:04 +00001538 OS << "None, ";
Andrew Tricka72fca62012-09-17 22:18:50 +00001539 OS << '\n'; OS.indent(22);
Andrew Trickab722bd2012-09-18 03:18:56 +00001540 OS << Target << "ProcSchedKV, "
1541 << Target << "WriteProcResTable, "
1542 << Target << "WriteLatencyTable, "
1543 << Target << "ReadAdvanceTable, ";
Eugene Zelenko2bc2f332016-12-09 22:06:55 +00001544 OS << '\n'; OS.indent(22);
Andrew Trickbf8a28d2013-03-16 18:58:55 +00001545 if (SchedModels.hasItineraries()) {
Andrew Trickab722bd2012-09-18 03:18:56 +00001546 OS << Target << "Stages, "
Evan Cheng54b68e32011-07-01 20:45:01 +00001547 << Target << "OperandCycles, "
Eric Christopherdc5072d2014-05-06 20:23:04 +00001548 << Target << "ForwardingPaths";
Evan Cheng54b68e32011-07-01 20:45:01 +00001549 } else
Eugene Zelenko2bc2f332016-12-09 22:06:55 +00001550 OS << "nullptr, nullptr, nullptr";
Eric Christopherdc5072d2014-05-06 20:23:04 +00001551 OS << ");\n}\n\n";
Evan Cheng54b68e32011-07-01 20:45:01 +00001552
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001553 OS << "} // end namespace llvm\n\n";
Evan Cheng54b68e32011-07-01 20:45:01 +00001554
1555 OS << "#endif // GET_SUBTARGETINFO_MC_DESC\n\n";
1556
1557 OS << "\n#ifdef GET_SUBTARGETINFO_TARGET_DESC\n";
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001558 OS << "#undef GET_SUBTARGETINFO_TARGET_DESC\n\n";
Evan Cheng54b68e32011-07-01 20:45:01 +00001559
1560 OS << "#include \"llvm/Support/Debug.h\"\n";
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001561 OS << "#include \"llvm/Support/raw_ostream.h\"\n\n";
Evan Cheng54b68e32011-07-01 20:45:01 +00001562 ParseFeaturesFunction(OS, NumFeatures, NumProcs);
1563
1564 OS << "#endif // GET_SUBTARGETINFO_TARGET_DESC\n\n";
1565
Evan Cheng0d639a22011-07-01 21:01:15 +00001566 // Create a TargetSubtargetInfo subclass to hide the MC layer initialization.
Evan Cheng54b68e32011-07-01 20:45:01 +00001567 OS << "\n#ifdef GET_SUBTARGETINFO_HEADER\n";
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001568 OS << "#undef GET_SUBTARGETINFO_HEADER\n\n";
Evan Cheng54b68e32011-07-01 20:45:01 +00001569
1570 std::string ClassName = Target + "GenSubtargetInfo";
1571 OS << "namespace llvm {\n";
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +00001572 OS << "class DFAPacketizer;\n";
Evan Cheng0d639a22011-07-01 21:01:15 +00001573 OS << "struct " << ClassName << " : public TargetSubtargetInfo {\n"
Daniel Sanders50f17232015-09-15 16:17:27 +00001574 << " explicit " << ClassName << "(const Triple &TT, StringRef CPU, "
Evan Cheng1a72add62011-07-07 07:07:08 +00001575 << "StringRef FS);\n"
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +00001576 << "public:\n"
Daniel Sandersa73f1fd2015-06-10 12:11:26 +00001577 << " unsigned resolveSchedClass(unsigned SchedClass, "
1578 << " const MachineInstr *DefMI,"
Craig Topper2d9361e2014-03-09 07:44:38 +00001579 << " const TargetSchedModel *SchedModel) const override;\n"
Sebastian Popac35a4d2011-12-06 17:34:16 +00001580 << " DFAPacketizer *createDFAPacketizer(const InstrItineraryData *IID)"
Krzysztof Parzyszek788e7682017-09-14 20:44:20 +00001581 << " const;\n";
1582 if (TGT.getHwModes().getNumModeIds() > 1)
1583 OS << " unsigned getHwMode() const override;\n";
1584 OS << "};\n"
1585 << "} // end namespace llvm\n\n";
Evan Cheng54b68e32011-07-01 20:45:01 +00001586
1587 OS << "#endif // GET_SUBTARGETINFO_HEADER\n\n";
1588
1589 OS << "\n#ifdef GET_SUBTARGETINFO_CTOR\n";
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001590 OS << "#undef GET_SUBTARGETINFO_CTOR\n\n";
Evan Cheng54b68e32011-07-01 20:45:01 +00001591
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001592 OS << "#include \"llvm/CodeGen/TargetSchedule.h\"\n\n";
Evan Cheng54b68e32011-07-01 20:45:01 +00001593 OS << "namespace llvm {\n";
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00001594 OS << "extern const llvm::SubtargetFeatureKV " << Target << "FeatureKV[];\n";
1595 OS << "extern const llvm::SubtargetFeatureKV " << Target << "SubTypeKV[];\n";
Andrew Tricka72fca62012-09-17 22:18:50 +00001596 OS << "extern const llvm::SubtargetInfoKV " << Target << "ProcSchedKV[];\n";
1597 OS << "extern const llvm::MCWriteProcResEntry "
1598 << Target << "WriteProcResTable[];\n";
1599 OS << "extern const llvm::MCWriteLatencyEntry "
1600 << Target << "WriteLatencyTable[];\n";
1601 OS << "extern const llvm::MCReadAdvanceEntry "
1602 << Target << "ReadAdvanceTable[];\n";
1603
Andrew Trickbf8a28d2013-03-16 18:58:55 +00001604 if (SchedModels.hasItineraries()) {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00001605 OS << "extern const llvm::InstrStage " << Target << "Stages[];\n";
1606 OS << "extern const unsigned " << Target << "OperandCycles[];\n";
Andrew Trick030e2f82012-07-07 03:59:48 +00001607 OS << "extern const unsigned " << Target << "ForwardingPaths[];\n";
Evan Chengbc153d42011-07-14 20:59:42 +00001608 }
1609
Daniel Sanders50f17232015-09-15 16:17:27 +00001610 OS << ClassName << "::" << ClassName << "(const Triple &TT, StringRef CPU, "
1611 << "StringRef FS)\n"
Duncan P. N. Exon Smith754e21f2015-07-10 22:43:42 +00001612 << " : TargetSubtargetInfo(TT, CPU, FS, ";
Evan Cheng54b68e32011-07-01 20:45:01 +00001613 if (NumFeatures)
Eric Christopherdc5072d2014-05-06 20:23:04 +00001614 OS << "makeArrayRef(" << Target << "FeatureKV, " << NumFeatures << "), ";
Evan Cheng54b68e32011-07-01 20:45:01 +00001615 else
Eric Christopherdc5072d2014-05-06 20:23:04 +00001616 OS << "None, ";
Evan Cheng54b68e32011-07-01 20:45:01 +00001617 if (NumProcs)
Eric Christopherdc5072d2014-05-06 20:23:04 +00001618 OS << "makeArrayRef(" << Target << "SubTypeKV, " << NumProcs << "), ";
Evan Cheng54b68e32011-07-01 20:45:01 +00001619 else
Eric Christopherdc5072d2014-05-06 20:23:04 +00001620 OS << "None, ";
Duncan P. N. Exon Smith754e21f2015-07-10 22:43:42 +00001621 OS << '\n'; OS.indent(24);
Andrew Trickab722bd2012-09-18 03:18:56 +00001622 OS << Target << "ProcSchedKV, "
1623 << Target << "WriteProcResTable, "
1624 << Target << "WriteLatencyTable, "
1625 << Target << "ReadAdvanceTable, ";
Duncan P. N. Exon Smith754e21f2015-07-10 22:43:42 +00001626 OS << '\n'; OS.indent(24);
Andrew Trickbf8a28d2013-03-16 18:58:55 +00001627 if (SchedModels.hasItineraries()) {
Andrew Trickab722bd2012-09-18 03:18:56 +00001628 OS << Target << "Stages, "
Evan Cheng54b68e32011-07-01 20:45:01 +00001629 << Target << "OperandCycles, "
Eric Christopherdc5072d2014-05-06 20:23:04 +00001630 << Target << "ForwardingPaths";
Evan Cheng54b68e32011-07-01 20:45:01 +00001631 } else
Eugene Zelenko2bc2f332016-12-09 22:06:55 +00001632 OS << "nullptr, nullptr, nullptr";
Duncan P. N. Exon Smith754e21f2015-07-10 22:43:42 +00001633 OS << ") {}\n\n";
Andrew Tricka72fca62012-09-17 22:18:50 +00001634
Andrew Trickc6c88152012-09-18 03:41:43 +00001635 EmitSchedModelHelpers(ClassName, OS);
Krzysztof Parzyszek788e7682017-09-14 20:44:20 +00001636 EmitHwModeCheck(ClassName, OS);
Andrew Trickc6c88152012-09-18 03:41:43 +00001637
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001638 OS << "} // end namespace llvm\n\n";
Evan Cheng54b68e32011-07-01 20:45:01 +00001639
1640 OS << "#endif // GET_SUBTARGETINFO_CTOR\n\n";
Jim Laskeycfda85a2005-10-21 19:00:04 +00001641}
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +00001642
1643namespace llvm {
1644
1645void EmitSubtarget(RecordKeeper &RK, raw_ostream &OS) {
Andrew Trick87255e32012-07-07 04:00:00 +00001646 CodeGenTarget CGTarget(RK);
1647 SubtargetEmitter(RK, CGTarget).run(OS);
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +00001648}
1649
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001650} // end namespace llvm