blob: 30d76f782a7b7bc20f3cd76b1e10c490cb59bbc5 [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 Biagio9da4d6d2018-04-03 13:36:24 +000093 void EmitExtraProcessorInfo(const CodeGenProcModel &ProcModel, raw_ostream &OS);
Mehdi Amini32986ed2016-10-04 23:47:33 +000094 void EmitProcessorProp(raw_ostream &OS, const Record *R, StringRef Name,
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +000095 char Separator);
Clement Courbet39911e22018-02-08 08:46:48 +000096 void EmitProcessorResourceSubUnits(const CodeGenProcModel &ProcModel,
97 raw_ostream &OS);
Andrew Trick23f3c652012-09-17 22:18:45 +000098 void EmitProcessorResources(const CodeGenProcModel &ProcModel,
99 raw_ostream &OS);
Andrew Trick9257b8f2012-09-22 02:24:21 +0000100 Record *FindWriteResources(const CodeGenSchedRW &SchedWrite,
Andrew Trick9ef08822012-09-17 22:18:48 +0000101 const CodeGenProcModel &ProcModel);
Andrew Trick9257b8f2012-09-22 02:24:21 +0000102 Record *FindReadAdvance(const CodeGenSchedRW &SchedRead,
103 const CodeGenProcModel &ProcModel);
Andrew Trick4e67cba2013-03-14 21:21:50 +0000104 void ExpandProcResources(RecVec &PRVec, std::vector<int64_t> &Cycles,
105 const CodeGenProcModel &ProcModel);
Andrew Trick9ef08822012-09-17 22:18:48 +0000106 void GenSchedClassTables(const CodeGenProcModel &ProcModel,
107 SchedClassTables &SchedTables);
Andrew Tricka72fca62012-09-17 22:18:50 +0000108 void EmitSchedClassTables(SchedClassTables &SchedTables, raw_ostream &OS);
Andrew Trick87255e32012-07-07 04:00:00 +0000109 void EmitProcessorModels(raw_ostream &OS);
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +0000110 void EmitProcessorLookup(raw_ostream &OS);
Benjamin Kramerc321e532016-06-08 19:09:22 +0000111 void EmitSchedModelHelpers(const std::string &ClassName, raw_ostream &OS);
Andrew Trick87255e32012-07-07 04:00:00 +0000112 void EmitSchedModel(raw_ostream &OS);
Krzysztof Parzyszek788e7682017-09-14 20:44:20 +0000113 void EmitHwModeCheck(const std::string &ClassName, raw_ostream &OS);
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +0000114 void ParseFeaturesFunction(raw_ostream &OS, unsigned NumFeatures,
115 unsigned NumProcs);
116
117public:
Krzysztof Parzyszek788e7682017-09-14 20:44:20 +0000118 SubtargetEmitter(RecordKeeper &R, CodeGenTarget &TGT)
119 : TGT(TGT), Records(R), SchedModels(TGT.getSchedModels()),
120 Target(TGT.getName()) {}
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +0000121
122 void run(raw_ostream &o);
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +0000123};
Eugene Zelenko75259bb2016-05-17 17:04:23 +0000124
Hans Wennborg083ca9b2015-10-06 23:24:35 +0000125} // end anonymous namespace
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +0000126
Jim Laskeya1beea62005-10-22 07:59:56 +0000127//
Jim Laskeya2b52352005-10-26 17:30:34 +0000128// Enumeration - Emit the specified class as an enumeration.
Jim Laskey1b7369b2005-10-25 15:16:36 +0000129//
Craig Topper094bbca2016-02-14 05:22:01 +0000130void SubtargetEmitter::Enumeration(raw_ostream &OS) {
Jim Laskey19595752005-10-28 15:20:43 +0000131 // Get all records of class and sort
Craig Topper094bbca2016-02-14 05:22:01 +0000132 std::vector<Record*> DefList =
133 Records.getAllDerivedDefinitions("SubtargetFeature");
Duraid Madina018da4f2005-12-30 14:56:37 +0000134 std::sort(DefList.begin(), DefList.end(), LessRecord());
Jim Laskey1b7369b2005-10-25 15:16:36 +0000135
Evan Chenga2e61292011-04-15 19:35:46 +0000136 unsigned N = DefList.size();
Evan Cheng54b68e32011-07-01 20:45:01 +0000137 if (N == 0)
138 return;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000139 if (N > MAX_SUBTARGET_FEATURES)
140 PrintFatalError("Too many subtarget features! Bump MAX_SUBTARGET_FEATURES.");
Evan Chenga2e61292011-04-15 19:35:46 +0000141
Evan Cheng54b68e32011-07-01 20:45:01 +0000142 OS << "namespace " << Target << " {\n";
143
Craig Topperbcdb0f22016-02-13 17:58:14 +0000144 // Open enumeration.
Craig Topper2d45c1d2016-02-13 06:03:29 +0000145 OS << "enum {\n";
Evan Cheng54b68e32011-07-01 20:45:01 +0000146
Reid Kleckner294fa7a2015-03-09 20:23:14 +0000147 // For each record
Craig Topperdf1285b2017-10-24 15:50:53 +0000148 for (unsigned i = 0; i < N; ++i) {
Reid Kleckner294fa7a2015-03-09 20:23:14 +0000149 // Next record
150 Record *Def = DefList[i];
Andrew Trickdb6ed642011-04-01 01:56:55 +0000151
Reid Kleckner294fa7a2015-03-09 20:23:14 +0000152 // Get and emit name
Craig Topperdf1285b2017-10-24 15:50:53 +0000153 OS << " " << Def->getName() << " = " << i << ",\n";
Jim Laskey1b7369b2005-10-25 15:16:36 +0000154 }
Andrew Trickdb6ed642011-04-01 01:56:55 +0000155
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000156 // Close enumeration and namespace
Eugene Zelenko75259bb2016-05-17 17:04:23 +0000157 OS << "};\n";
158 OS << "} // end namespace " << Target << "\n";
Jim Laskey1b7369b2005-10-25 15:16:36 +0000159}
160
161//
Bill Wendlinge6182262007-05-04 20:38:40 +0000162// FeatureKeyValues - Emit data of all the subtarget features. Used by the
163// command line.
Jim Laskey1b7369b2005-10-25 15:16:36 +0000164//
Evan Cheng54b68e32011-07-01 20:45:01 +0000165unsigned SubtargetEmitter::FeatureKeyValues(raw_ostream &OS) {
Jim Laskey19595752005-10-28 15:20:43 +0000166 // Gather and sort all the features
Jim Laskeydffe5972005-10-28 21:47:29 +0000167 std::vector<Record*> FeatureList =
168 Records.getAllDerivedDefinitions("SubtargetFeature");
Evan Cheng54b68e32011-07-01 20:45:01 +0000169
170 if (FeatureList.empty())
171 return 0;
172
Jim Grosbach56938af2008-09-11 17:05:32 +0000173 std::sort(FeatureList.begin(), FeatureList.end(), LessRecordFieldName());
Jim Laskey1b7369b2005-10-25 15:16:36 +0000174
Jim Laskey19595752005-10-28 15:20:43 +0000175 // Begin feature table
Jim Laskeya2b52352005-10-26 17:30:34 +0000176 OS << "// Sorted (by key) array of values for CPU features.\n"
Benjamin Kramer0d6d0982011-10-22 16:50:00 +0000177 << "extern const llvm::SubtargetFeatureKV " << Target
178 << "FeatureKV[] = {\n";
Andrew Trickdb6ed642011-04-01 01:56:55 +0000179
Jim Laskey19595752005-10-28 15:20:43 +0000180 // For each feature
Evan Cheng54b68e32011-07-01 20:45:01 +0000181 unsigned NumFeatures = 0;
Jim Laskey3f7d0472006-12-12 20:55:58 +0000182 for (unsigned i = 0, N = FeatureList.size(); i < N; ++i) {
Jim Laskeydffe5972005-10-28 21:47:29 +0000183 // Next feature
184 Record *Feature = FeatureList[i];
185
Craig Topperbcd3c372017-05-31 21:12:46 +0000186 StringRef Name = Feature->getName();
187 StringRef CommandLineName = Feature->getValueAsString("Name");
188 StringRef Desc = Feature->getValueAsString("Desc");
Andrew Trickdb6ed642011-04-01 01:56:55 +0000189
Jim Laskey3f7d0472006-12-12 20:55:58 +0000190 if (CommandLineName.empty()) continue;
Andrew Trickdb6ed642011-04-01 01:56:55 +0000191
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000192 // Emit as { "feature", "description", { featureEnum }, { i1 , i2 , ... , in } }
Jim Laskey1b7369b2005-10-25 15:16:36 +0000193 OS << " { "
Jim Laskeydffe5972005-10-28 21:47:29 +0000194 << "\"" << CommandLineName << "\", "
Jim Laskey1b7369b2005-10-25 15:16:36 +0000195 << "\"" << Desc << "\", "
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000196 << "{ " << Target << "::" << Name << " }, ";
Bill Wendlinge6182262007-05-04 20:38:40 +0000197
Craig Topper37eeb322018-03-23 00:02:45 +0000198 RecVec ImpliesList = Feature->getValueAsListOfDefs("Implies");
Andrew Trickdb6ed642011-04-01 01:56:55 +0000199
Craig Topper4ceea0a2016-01-03 08:57:41 +0000200 OS << "{";
201 for (unsigned j = 0, M = ImpliesList.size(); j < M;) {
202 OS << " " << Target << "::" << ImpliesList[j]->getName();
203 if (++j < M) OS << ",";
Bill Wendlinge6182262007-05-04 20:38:40 +0000204 }
Craig Topperdf1285b2017-10-24 15:50:53 +0000205 OS << " } },\n";
Evan Cheng54b68e32011-07-01 20:45:01 +0000206 ++NumFeatures;
Jim Laskey1b7369b2005-10-25 15:16:36 +0000207 }
Andrew Trickdb6ed642011-04-01 01:56:55 +0000208
Jim Laskey19595752005-10-28 15:20:43 +0000209 // End feature table
Jim Laskey1b7369b2005-10-25 15:16:36 +0000210 OS << "};\n";
211
Evan Cheng54b68e32011-07-01 20:45:01 +0000212 return NumFeatures;
Jim Laskey1b7369b2005-10-25 15:16:36 +0000213}
214
215//
216// CPUKeyValues - Emit data of all the subtarget processors. Used by command
217// line.
218//
Evan Cheng54b68e32011-07-01 20:45:01 +0000219unsigned SubtargetEmitter::CPUKeyValues(raw_ostream &OS) {
Jim Laskey19595752005-10-28 15:20:43 +0000220 // Gather and sort processor information
Jim Laskeydffe5972005-10-28 21:47:29 +0000221 std::vector<Record*> ProcessorList =
222 Records.getAllDerivedDefinitions("Processor");
Duraid Madina018da4f2005-12-30 14:56:37 +0000223 std::sort(ProcessorList.begin(), ProcessorList.end(), LessRecordFieldName());
Jim Laskey1b7369b2005-10-25 15:16:36 +0000224
Jim Laskey19595752005-10-28 15:20:43 +0000225 // Begin processor table
Jim Laskeya2b52352005-10-26 17:30:34 +0000226 OS << "// Sorted (by key) array of values for CPU subtype.\n"
Benjamin Kramer0d6d0982011-10-22 16:50:00 +0000227 << "extern const llvm::SubtargetFeatureKV " << Target
228 << "SubTypeKV[] = {\n";
Andrew Trickdb6ed642011-04-01 01:56:55 +0000229
Jim Laskey19595752005-10-28 15:20:43 +0000230 // For each processor
Craig Topperdf1285b2017-10-24 15:50:53 +0000231 for (Record *Processor : ProcessorList) {
Craig Topperbcd3c372017-05-31 21:12:46 +0000232 StringRef Name = Processor->getValueAsString("Name");
Craig Topper37eeb322018-03-23 00:02:45 +0000233 RecVec FeatureList = Processor->getValueAsListOfDefs("Features");
Andrew Trickdb6ed642011-04-01 01:56:55 +0000234
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000235 // Emit as { "cpu", "description", { f1 , f2 , ... fn } },
Jim Laskey1b7369b2005-10-25 15:16:36 +0000236 OS << " { "
237 << "\"" << Name << "\", "
238 << "\"Select the " << Name << " processor\", ";
Andrew Trickdb6ed642011-04-01 01:56:55 +0000239
Craig Topper4ceea0a2016-01-03 08:57:41 +0000240 OS << "{";
241 for (unsigned j = 0, M = FeatureList.size(); j < M;) {
242 OS << " " << Target << "::" << FeatureList[j]->getName();
243 if (++j < M) OS << ",";
Jim Laskey1b7369b2005-10-25 15:16:36 +0000244 }
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000245 // The { } is for the "implies" section of this data structure.
Craig Topperdf1285b2017-10-24 15:50:53 +0000246 OS << " }, { } },\n";
Jim Laskey1b7369b2005-10-25 15:16:36 +0000247 }
Andrew Trickdb6ed642011-04-01 01:56:55 +0000248
Jim Laskey19595752005-10-28 15:20:43 +0000249 // End processor table
Jim Laskey1b7369b2005-10-25 15:16:36 +0000250 OS << "};\n";
251
Evan Cheng54b68e32011-07-01 20:45:01 +0000252 return ProcessorList.size();
Jim Laskey1b7369b2005-10-25 15:16:36 +0000253}
Jim Laskeya1beea62005-10-22 07:59:56 +0000254
Jim Laskeya2b52352005-10-26 17:30:34 +0000255//
David Goodwind813cbf2009-08-17 16:02:57 +0000256// FormItineraryStageString - Compose a string containing the stage
257// data initialization for the specified itinerary. N is the number
258// of stages.
Jim Laskey86f002c2005-10-27 19:47:21 +0000259//
Anton Korobeynikov7d62e332010-04-18 20:31:01 +0000260void SubtargetEmitter::FormItineraryStageString(const std::string &Name,
261 Record *ItinData,
David Goodwind813cbf2009-08-17 16:02:57 +0000262 std::string &ItinString,
263 unsigned &NStages) {
Jim Laskeydffe5972005-10-28 21:47:29 +0000264 // Get states list
Craig Topper37eeb322018-03-23 00:02:45 +0000265 RecVec StageList = ItinData->getValueAsListOfDefs("Stages");
Jim Laskey19595752005-10-28 15:20:43 +0000266
267 // For each stage
Jim Laskeydffe5972005-10-28 21:47:29 +0000268 unsigned N = NStages = StageList.size();
Christopher Lamb8996dce2007-04-22 09:04:24 +0000269 for (unsigned i = 0; i < N;) {
Jim Laskeydffe5972005-10-28 21:47:29 +0000270 // Next stage
Bill Wendlinge6182262007-05-04 20:38:40 +0000271 const Record *Stage = StageList[i];
Andrew Trickdb6ed642011-04-01 01:56:55 +0000272
Anton Korobeynikov0bdc6342010-04-07 18:19:32 +0000273 // Form string as ,{ cycles, u1 | u2 | ... | un, timeinc, kind }
Jim Laskey86f002c2005-10-27 19:47:21 +0000274 int Cycles = Stage->getValueAsInt("Cycles");
Jim Laskeyd6d3afb2005-11-03 22:47:41 +0000275 ItinString += " { " + itostr(Cycles) + ", ";
Andrew Trickdb6ed642011-04-01 01:56:55 +0000276
Jim Laskeydffe5972005-10-28 21:47:29 +0000277 // Get unit list
Craig Topper37eeb322018-03-23 00:02:45 +0000278 RecVec UnitList = Stage->getValueAsListOfDefs("Units");
Andrew Trickdb6ed642011-04-01 01:56:55 +0000279
Jim Laskey19595752005-10-28 15:20:43 +0000280 // For each unit
Jim Laskeydffe5972005-10-28 21:47:29 +0000281 for (unsigned j = 0, M = UnitList.size(); j < M;) {
Jim Laskeydffe5972005-10-28 21:47:29 +0000282 // Add name and bitwise or
Matthias Braun4a86d452016-12-04 05:48:16 +0000283 ItinString += Name + "FU::" + UnitList[j]->getName().str();
Jim Laskeydffe5972005-10-28 21:47:29 +0000284 if (++j < M) ItinString += " | ";
Jim Laskey86f002c2005-10-27 19:47:21 +0000285 }
Andrew Trickdb6ed642011-04-01 01:56:55 +0000286
David Goodwinb369ee42009-08-12 18:31:53 +0000287 int TimeInc = Stage->getValueAsInt("TimeInc");
288 ItinString += ", " + itostr(TimeInc);
289
Anton Korobeynikov0bdc6342010-04-07 18:19:32 +0000290 int Kind = Stage->getValueAsInt("Kind");
291 ItinString += ", (llvm::InstrStage::ReservationKinds)" + itostr(Kind);
292
Jim Laskey19595752005-10-28 15:20:43 +0000293 // Close off stage
294 ItinString += " }";
Christopher Lamb8996dce2007-04-22 09:04:24 +0000295 if (++i < N) ItinString += ", ";
Jim Laskey86f002c2005-10-27 19:47:21 +0000296 }
Jim Laskey86f002c2005-10-27 19:47:21 +0000297}
298
299//
David Goodwind813cbf2009-08-17 16:02:57 +0000300// FormItineraryOperandCycleString - Compose a string containing the
301// operand cycle initialization for the specified itinerary. N is the
302// number of operands that has cycles specified.
Jim Laskey86f002c2005-10-27 19:47:21 +0000303//
David Goodwind813cbf2009-08-17 16:02:57 +0000304void SubtargetEmitter::FormItineraryOperandCycleString(Record *ItinData,
305 std::string &ItinString, unsigned &NOperandCycles) {
306 // Get operand cycle list
Craig Topper37eeb322018-03-23 00:02:45 +0000307 std::vector<int64_t> OperandCycleList =
David Goodwind813cbf2009-08-17 16:02:57 +0000308 ItinData->getValueAsListOfInts("OperandCycles");
309
310 // For each operand cycle
311 unsigned N = NOperandCycles = OperandCycleList.size();
312 for (unsigned i = 0; i < N;) {
313 // Next operand cycle
314 const int OCycle = OperandCycleList[i];
Andrew Trickdb6ed642011-04-01 01:56:55 +0000315
David Goodwind813cbf2009-08-17 16:02:57 +0000316 ItinString += " " + itostr(OCycle);
317 if (++i < N) ItinString += ", ";
318 }
319}
320
Evan Cheng0097dd02010-09-28 23:50:49 +0000321void SubtargetEmitter::FormItineraryBypassString(const std::string &Name,
322 Record *ItinData,
323 std::string &ItinString,
324 unsigned NOperandCycles) {
Craig Topper37eeb322018-03-23 00:02:45 +0000325 RecVec BypassList = ItinData->getValueAsListOfDefs("Bypasses");
Evan Cheng0097dd02010-09-28 23:50:49 +0000326 unsigned N = BypassList.size();
Evan Cheng4a010fd2010-09-29 22:42:35 +0000327 unsigned i = 0;
328 for (; i < N;) {
Matthias Braun4a86d452016-12-04 05:48:16 +0000329 ItinString += Name + "Bypass::" + BypassList[i]->getName().str();
Evan Cheng4a010fd2010-09-29 22:42:35 +0000330 if (++i < NOperandCycles) ItinString += ", ";
Evan Cheng0097dd02010-09-28 23:50:49 +0000331 }
Evan Cheng4a010fd2010-09-29 22:42:35 +0000332 for (; i < NOperandCycles;) {
Evan Cheng0097dd02010-09-28 23:50:49 +0000333 ItinString += " 0";
Evan Cheng4a010fd2010-09-29 22:42:35 +0000334 if (++i < NOperandCycles) ItinString += ", ";
Evan Cheng0097dd02010-09-28 23:50:49 +0000335 }
336}
337
David Goodwind813cbf2009-08-17 16:02:57 +0000338//
Andrew Trick87255e32012-07-07 04:00:00 +0000339// EmitStageAndOperandCycleData - Generate unique itinerary stages and operand
340// cycle tables. Create a list of InstrItinerary objects (ProcItinLists) indexed
341// by CodeGenSchedClass::Index.
David Goodwind813cbf2009-08-17 16:02:57 +0000342//
Andrew Trick87255e32012-07-07 04:00:00 +0000343void SubtargetEmitter::
344EmitStageAndOperandCycleData(raw_ostream &OS,
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000345 std::vector<std::vector<InstrItinerary>>
Andrew Trick87255e32012-07-07 04:00:00 +0000346 &ProcItinLists) {
Andrew Trickfb982dd2012-07-09 20:43:03 +0000347 // Multiple processor models may share an itinerary record. Emit it once.
348 SmallPtrSet<Record*, 8> ItinsDefSet;
349
Anton Korobeynikov7d62e332010-04-18 20:31:01 +0000350 // Emit functional units for all the itineraries.
Craig Topper29c55dcb2016-02-13 06:03:32 +0000351 for (const CodeGenProcModel &ProcModel : SchedModels.procModels()) {
Anton Korobeynikov7d62e332010-04-18 20:31:01 +0000352
Craig Topper29c55dcb2016-02-13 06:03:32 +0000353 if (!ItinsDefSet.insert(ProcModel.ItinsDef).second)
Andrew Trickfb982dd2012-07-09 20:43:03 +0000354 continue;
355
Craig Topper37eeb322018-03-23 00:02:45 +0000356 RecVec FUs = ProcModel.ItinsDef->getValueAsListOfDefs("FU");
Anton Korobeynikov7d62e332010-04-18 20:31:01 +0000357 if (FUs.empty())
358 continue;
359
Alexander Shaposhnikovd968f6f2017-07-05 20:14:54 +0000360 StringRef Name = ProcModel.ItinsDef->getName();
Andrew Trick87255e32012-07-07 04:00:00 +0000361 OS << "\n// Functional units for \"" << Name << "\"\n"
Anton Korobeynikov7d62e332010-04-18 20:31:01 +0000362 << "namespace " << Name << "FU {\n";
363
364 for (unsigned j = 0, FUN = FUs.size(); j < FUN; ++j)
Hal Finkel8db55472012-06-22 20:27:13 +0000365 OS << " const unsigned " << FUs[j]->getName()
366 << " = 1 << " << j << ";\n";
Anton Korobeynikov7d62e332010-04-18 20:31:01 +0000367
Eugene Zelenko75259bb2016-05-17 17:04:23 +0000368 OS << "} // end namespace " << Name << "FU\n";
Evan Cheng0097dd02010-09-28 23:50:49 +0000369
Craig Topper37eeb322018-03-23 00:02:45 +0000370 RecVec BPs = ProcModel.ItinsDef->getValueAsListOfDefs("BP");
Alexander Kornienko8c0809c2015-01-15 11:41:30 +0000371 if (!BPs.empty()) {
Sylvestre Ledru543f15b2018-03-17 17:30:08 +0000372 OS << "\n// Pipeline forwarding paths for itineraries \"" << Name
Evan Cheng4a010fd2010-09-29 22:42:35 +0000373 << "\"\n" << "namespace " << Name << "Bypass {\n";
Evan Cheng0097dd02010-09-28 23:50:49 +0000374
Benjamin Kramer0d6d0982011-10-22 16:50:00 +0000375 OS << " const unsigned NoBypass = 0;\n";
Evan Cheng4a010fd2010-09-29 22:42:35 +0000376 for (unsigned j = 0, BPN = BPs.size(); j < BPN; ++j)
Benjamin Kramer0d6d0982011-10-22 16:50:00 +0000377 OS << " const unsigned " << BPs[j]->getName()
Evan Cheng4a010fd2010-09-29 22:42:35 +0000378 << " = 1 << " << j << ";\n";
Evan Cheng0097dd02010-09-28 23:50:49 +0000379
Eugene Zelenko75259bb2016-05-17 17:04:23 +0000380 OS << "} // end namespace " << Name << "Bypass\n";
Evan Cheng4a010fd2010-09-29 22:42:35 +0000381 }
Anton Korobeynikov7d62e332010-04-18 20:31:01 +0000382 }
383
Jim Laskey19595752005-10-28 15:20:43 +0000384 // Begin stages table
Benjamin Kramer0d6d0982011-10-22 16:50:00 +0000385 std::string StageTable = "\nextern const llvm::InstrStage " + Target +
386 "Stages[] = {\n";
Anton Korobeynikov0bdc6342010-04-07 18:19:32 +0000387 StageTable += " { 0, 0, 0, llvm::InstrStage::Required }, // No itinerary\n";
Andrew Trickdb6ed642011-04-01 01:56:55 +0000388
David Goodwind813cbf2009-08-17 16:02:57 +0000389 // Begin operand cycle table
Benjamin Kramer0d6d0982011-10-22 16:50:00 +0000390 std::string OperandCycleTable = "extern const unsigned " + Target +
Evan Cheng54b68e32011-07-01 20:45:01 +0000391 "OperandCycles[] = {\n";
David Goodwind813cbf2009-08-17 16:02:57 +0000392 OperandCycleTable += " 0, // No itinerary\n";
Evan Cheng0097dd02010-09-28 23:50:49 +0000393
394 // Begin pipeline bypass table
Benjamin Kramer0d6d0982011-10-22 16:50:00 +0000395 std::string BypassTable = "extern const unsigned " + Target +
Andrew Trick030e2f82012-07-07 03:59:48 +0000396 "ForwardingPaths[] = {\n";
Andrew Trick87255e32012-07-07 04:00:00 +0000397 BypassTable += " 0, // No itinerary\n";
Andrew Trickdb6ed642011-04-01 01:56:55 +0000398
Andrew Trick87255e32012-07-07 04:00:00 +0000399 // For each Itinerary across all processors, add a unique entry to the stages,
Geoff Berryb2cfea52017-05-08 15:33:08 +0000400 // operand cycles, and pipeline bypass tables. Then add the new Itinerary
Andrew Trick87255e32012-07-07 04:00:00 +0000401 // object with computed offsets to the ProcItinLists result.
David Goodwind813cbf2009-08-17 16:02:57 +0000402 unsigned StageCount = 1, OperandCycleCount = 1;
Evan Cheng4a010fd2010-09-29 22:42:35 +0000403 std::map<std::string, unsigned> ItinStageMap, ItinOperandMap;
Craig Topper29c55dcb2016-02-13 06:03:32 +0000404 for (const CodeGenProcModel &ProcModel : SchedModels.procModels()) {
Andrew Trick87255e32012-07-07 04:00:00 +0000405 // Add process itinerary to the list.
406 ProcItinLists.resize(ProcItinLists.size()+1);
Andrew Trickdb6ed642011-04-01 01:56:55 +0000407
Andrew Trick87255e32012-07-07 04:00:00 +0000408 // If this processor defines no itineraries, then leave the itinerary list
409 // empty.
410 std::vector<InstrItinerary> &ItinList = ProcItinLists.back();
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000411 if (!ProcModel.hasItineraries())
Andrew Trick9c302672012-06-22 03:58:51 +0000412 continue;
Andrew Trick9c302672012-06-22 03:58:51 +0000413
Alexander Shaposhnikovd968f6f2017-07-05 20:14:54 +0000414 StringRef Name = ProcModel.ItinsDef->getName();
Andrew Trickdb6ed642011-04-01 01:56:55 +0000415
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000416 ItinList.resize(SchedModels.numInstrSchedClasses());
417 assert(ProcModel.ItinDefList.size() == ItinList.size() && "bad Itins");
418
419 for (unsigned SchedClassIdx = 0, SchedClassEnd = ItinList.size();
Andrew Trick87255e32012-07-07 04:00:00 +0000420 SchedClassIdx < SchedClassEnd; ++SchedClassIdx) {
421
Jim Laskeydffe5972005-10-28 21:47:29 +0000422 // Next itinerary data
Andrew Trick87255e32012-07-07 04:00:00 +0000423 Record *ItinData = ProcModel.ItinDefList[SchedClassIdx];
Andrew Trickdb6ed642011-04-01 01:56:55 +0000424
Jim Laskey19595752005-10-28 15:20:43 +0000425 // Get string and stage count
David Goodwind813cbf2009-08-17 16:02:57 +0000426 std::string ItinStageString;
Andrew Trick87255e32012-07-07 04:00:00 +0000427 unsigned NStages = 0;
428 if (ItinData)
429 FormItineraryStageString(Name, ItinData, ItinStageString, NStages);
Jim Laskey86f002c2005-10-27 19:47:21 +0000430
David Goodwind813cbf2009-08-17 16:02:57 +0000431 // Get string and operand cycle count
432 std::string ItinOperandCycleString;
Andrew Trick87255e32012-07-07 04:00:00 +0000433 unsigned NOperandCycles = 0;
Evan Cheng0097dd02010-09-28 23:50:49 +0000434 std::string ItinBypassString;
Andrew Trick87255e32012-07-07 04:00:00 +0000435 if (ItinData) {
436 FormItineraryOperandCycleString(ItinData, ItinOperandCycleString,
437 NOperandCycles);
438
439 FormItineraryBypassString(Name, ItinData, ItinBypassString,
440 NOperandCycles);
441 }
Evan Cheng0097dd02010-09-28 23:50:49 +0000442
David Goodwind813cbf2009-08-17 16:02:57 +0000443 // Check to see if stage already exists and create if it doesn't
Benjamin Kramerb941aba2018-02-23 19:32:56 +0000444 uint16_t FindStage = 0;
David Goodwind813cbf2009-08-17 16:02:57 +0000445 if (NStages > 0) {
446 FindStage = ItinStageMap[ItinStageString];
447 if (FindStage == 0) {
Andrew Trick8a05f662011-04-01 02:22:47 +0000448 // Emit as { cycles, u1 | u2 | ... | un, timeinc }, // indices
449 StageTable += ItinStageString + ", // " + itostr(StageCount);
450 if (NStages > 1)
451 StageTable += "-" + itostr(StageCount + NStages - 1);
452 StageTable += "\n";
David Goodwind813cbf2009-08-17 16:02:57 +0000453 // Record Itin class number.
454 ItinStageMap[ItinStageString] = FindStage = StageCount;
455 StageCount += NStages;
David Goodwind813cbf2009-08-17 16:02:57 +0000456 }
457 }
Andrew Trickdb6ed642011-04-01 01:56:55 +0000458
David Goodwind813cbf2009-08-17 16:02:57 +0000459 // Check to see if operand cycle already exists and create if it doesn't
Benjamin Kramerb941aba2018-02-23 19:32:56 +0000460 uint16_t FindOperandCycle = 0;
David Goodwind813cbf2009-08-17 16:02:57 +0000461 if (NOperandCycles > 0) {
Evan Cheng4a010fd2010-09-29 22:42:35 +0000462 std::string ItinOperandString = ItinOperandCycleString+ItinBypassString;
463 FindOperandCycle = ItinOperandMap[ItinOperandString];
David Goodwind813cbf2009-08-17 16:02:57 +0000464 if (FindOperandCycle == 0) {
465 // Emit as cycle, // index
Andrew Trick8a05f662011-04-01 02:22:47 +0000466 OperandCycleTable += ItinOperandCycleString + ", // ";
467 std::string OperandIdxComment = itostr(OperandCycleCount);
468 if (NOperandCycles > 1)
469 OperandIdxComment += "-"
470 + itostr(OperandCycleCount + NOperandCycles - 1);
471 OperandCycleTable += OperandIdxComment + "\n";
David Goodwind813cbf2009-08-17 16:02:57 +0000472 // Record Itin class number.
Andrew Trickdb6ed642011-04-01 01:56:55 +0000473 ItinOperandMap[ItinOperandCycleString] =
David Goodwind813cbf2009-08-17 16:02:57 +0000474 FindOperandCycle = OperandCycleCount;
Evan Cheng0097dd02010-09-28 23:50:49 +0000475 // Emit as bypass, // index
Andrew Trick8a05f662011-04-01 02:22:47 +0000476 BypassTable += ItinBypassString + ", // " + OperandIdxComment + "\n";
David Goodwind813cbf2009-08-17 16:02:57 +0000477 OperandCycleCount += NOperandCycles;
David Goodwind813cbf2009-08-17 16:02:57 +0000478 }
Jim Laskey86f002c2005-10-27 19:47:21 +0000479 }
Andrew Trickdb6ed642011-04-01 01:56:55 +0000480
Evan Cheng367a5df2010-09-09 18:18:55 +0000481 // Set up itinerary as location and location + stage count
Benjamin Kramerb941aba2018-02-23 19:32:56 +0000482 int16_t NumUOps = ItinData ? ItinData->getValueAsInt("NumMicroOps") : 0;
483 InstrItinerary Intinerary = {
484 NumUOps,
485 FindStage,
486 uint16_t(FindStage + NStages),
487 FindOperandCycle,
488 uint16_t(FindOperandCycle + NOperandCycles),
489 };
Evan Cheng367a5df2010-09-09 18:18:55 +0000490
Jim Laskey19595752005-10-28 15:20:43 +0000491 // Inject - empty slots will be 0, 0
Andrew Trick87255e32012-07-07 04:00:00 +0000492 ItinList[SchedClassIdx] = Intinerary;
Jim Laskey86f002c2005-10-27 19:47:21 +0000493 }
Jim Laskey86f002c2005-10-27 19:47:21 +0000494 }
Evan Cheng0097dd02010-09-28 23:50:49 +0000495
Jim Laskeyd6d3afb2005-11-03 22:47:41 +0000496 // Closing stage
Andrew Trick87255e32012-07-07 04:00:00 +0000497 StageTable += " { 0, 0, 0, llvm::InstrStage::Required } // End stages\n";
David Goodwind813cbf2009-08-17 16:02:57 +0000498 StageTable += "};\n";
499
500 // Closing operand cycles
Andrew Trick87255e32012-07-07 04:00:00 +0000501 OperandCycleTable += " 0 // End operand cycles\n";
David Goodwind813cbf2009-08-17 16:02:57 +0000502 OperandCycleTable += "};\n";
503
Andrew Trick87255e32012-07-07 04:00:00 +0000504 BypassTable += " 0 // End bypass tables\n";
Evan Cheng0097dd02010-09-28 23:50:49 +0000505 BypassTable += "};\n";
506
David Goodwind813cbf2009-08-17 16:02:57 +0000507 // Emit tables.
508 OS << StageTable;
509 OS << OperandCycleTable;
Evan Cheng0097dd02010-09-28 23:50:49 +0000510 OS << BypassTable;
Jim Laskey86f002c2005-10-27 19:47:21 +0000511}
512
Andrew Trick87255e32012-07-07 04:00:00 +0000513//
514// EmitProcessorData - Generate data for processor itineraries that were
515// computed during EmitStageAndOperandCycleData(). ProcItinLists lists all
516// Itineraries for each processor. The Itinerary lists are indexed on
517// CodeGenSchedClass::Index.
518//
519void SubtargetEmitter::
520EmitItineraries(raw_ostream &OS,
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000521 std::vector<std::vector<InstrItinerary>> &ProcItinLists) {
Andrew Trickfb982dd2012-07-09 20:43:03 +0000522 // Multiple processor models may share an itinerary record. Emit it once.
523 SmallPtrSet<Record*, 8> ItinsDefSet;
524
Andrew Trick87255e32012-07-07 04:00:00 +0000525 // For each processor's machine model
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000526 std::vector<std::vector<InstrItinerary>>::iterator
Andrew Trick87255e32012-07-07 04:00:00 +0000527 ProcItinListsIter = ProcItinLists.begin();
528 for (CodeGenSchedModels::ProcIter PI = SchedModels.procModelBegin(),
Andrew Trick76686492012-09-15 00:19:57 +0000529 PE = SchedModels.procModelEnd(); PI != PE; ++PI, ++ProcItinListsIter) {
Andrew Trickfb982dd2012-07-09 20:43:03 +0000530
Andrew Trick87255e32012-07-07 04:00:00 +0000531 Record *ItinsDef = PI->ItinsDef;
David Blaikie70573dc2014-11-19 07:49:26 +0000532 if (!ItinsDefSet.insert(ItinsDef).second)
Andrew Trickfb982dd2012-07-09 20:43:03 +0000533 continue;
Andrew Trick87255e32012-07-07 04:00:00 +0000534
Andrew Trick87255e32012-07-07 04:00:00 +0000535 // Get the itinerary list for the processor.
536 assert(ProcItinListsIter != ProcItinLists.end() && "bad iterator");
Andrew Trick76686492012-09-15 00:19:57 +0000537 std::vector<InstrItinerary> &ItinList = *ProcItinListsIter;
Andrew Trick87255e32012-07-07 04:00:00 +0000538
Pete Cooperc0eb1532014-09-02 23:23:34 +0000539 // Empty itineraries aren't referenced anywhere in the tablegen output
540 // so don't emit them.
541 if (ItinList.empty())
542 continue;
543
Andrew Trick87255e32012-07-07 04:00:00 +0000544 OS << "\n";
545 OS << "static const llvm::InstrItinerary ";
Andrew Trick87255e32012-07-07 04:00:00 +0000546
547 // Begin processor itinerary table
Alexander Shaposhnikovd968f6f2017-07-05 20:14:54 +0000548 OS << ItinsDef->getName() << "[] = {\n";
Andrew Trick87255e32012-07-07 04:00:00 +0000549
550 // For each itinerary class in CodeGenSchedClass::Index order.
551 for (unsigned j = 0, M = ItinList.size(); j < M; ++j) {
552 InstrItinerary &Intinerary = ItinList[j];
553
554 // Emit Itinerary in the form of
555 // { firstStage, lastStage, firstCycle, lastCycle } // index
556 OS << " { " <<
557 Intinerary.NumMicroOps << ", " <<
558 Intinerary.FirstStage << ", " <<
559 Intinerary.LastStage << ", " <<
560 Intinerary.FirstOperandCycle << ", " <<
561 Intinerary.LastOperandCycle << " }" <<
562 ", // " << j << " " << SchedModels.getSchedClass(j).Name << "\n";
563 }
564 // End processor itinerary table
Benjamin Kramerb941aba2018-02-23 19:32:56 +0000565 OS << " { 0, uint16_t(~0U), uint16_t(~0U), uint16_t(~0U), uint16_t(~0U) }"
566 "// end marker\n";
Andrew Trick87255e32012-07-07 04:00:00 +0000567 OS << "};\n";
568 }
569}
570
Sylvestre Ledru35521e22012-07-23 08:51:15 +0000571// Emit either the value defined in the TableGen Record, or the default
Andrew Trick87255e32012-07-07 04:00:00 +0000572// value defined in the C++ header. The Record is null if the processor does not
573// define a model.
574void SubtargetEmitter::EmitProcessorProp(raw_ostream &OS, const Record *R,
Mehdi Amini32986ed2016-10-04 23:47:33 +0000575 StringRef Name, char Separator) {
Andrew Trick73d77362012-06-05 03:44:40 +0000576 OS << " ";
Andrew Trick87255e32012-07-07 04:00:00 +0000577 int V = R ? R->getValueAsInt(Name) : -1;
Andrew Trick73d77362012-06-05 03:44:40 +0000578 if (V >= 0)
579 OS << V << Separator << " // " << Name;
580 else
Andrew Trick87255e32012-07-07 04:00:00 +0000581 OS << "MCSchedModel::Default" << Name << Separator;
Andrew Trick73d77362012-06-05 03:44:40 +0000582 OS << '\n';
583}
584
Clement Courbet39911e22018-02-08 08:46:48 +0000585void SubtargetEmitter::EmitProcessorResourceSubUnits(
586 const CodeGenProcModel &ProcModel, raw_ostream &OS) {
587 OS << "\nstatic const unsigned " << ProcModel.ModelName
588 << "ProcResourceSubUnits[] = {\n"
589 << " 0, // Invalid\n";
590
591 for (unsigned i = 0, e = ProcModel.ProcResourceDefs.size(); i < e; ++i) {
592 Record *PRDef = ProcModel.ProcResourceDefs[i];
593 if (!PRDef->isSubClassOf("ProcResGroup"))
594 continue;
595 RecVec ResUnits = PRDef->getValueAsListOfDefs("Resources");
596 for (Record *RUDef : ResUnits) {
597 Record *const RU =
598 SchedModels.findProcResUnits(RUDef, ProcModel, PRDef->getLoc());
599 for (unsigned J = 0; J < RU->getValueAsInt("NumUnits"); ++J) {
600 OS << " " << ProcModel.getProcResourceIdx(RU) << ", ";
601 }
602 }
603 OS << " // " << PRDef->getName() << "\n";
604 }
605 OS << "};\n";
606}
607
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +0000608void SubtargetEmitter::EmitExtraProcessorInfo(const CodeGenProcModel &ProcModel,
609 raw_ostream &OS) {
610 if (llvm::all_of(ProcModel.RegisterFiles, [](const CodeGenRegisterFile &RF) {
611 return RF.hasDefaultCosts();
612 }))
613 return;
614
615 // Print the RegisterCost table first.
616 OS << "\n// {RegisterClassID, Register Cost}\n";
617 OS << "static const llvm::MCRegisterCostEntry " << ProcModel.ModelName
618 << "RegisterCosts"
619 << "[] = {\n";
620
621 for (const CodeGenRegisterFile &RF : ProcModel.RegisterFiles) {
622 // Skip register files with a default cost table.
623 if (RF.hasDefaultCosts())
624 continue;
625 // Add entries to the cost table.
626 for (const CodeGenRegisterCost &RC : RF.Costs) {
627 OS << " { ";
628 Record *Rec = RC.RCDef;
629 if (Rec->getValue("Namespace"))
630 OS << Rec->getValueAsString("Namespace") << "::";
631 OS << Rec->getName() << "RegClassID, " << RC.Cost << "},\n";
632 }
633 }
634 OS << "};\n";
635
636 // Now generate a table with register file info.
637 OS << "\n // {Name, #PhysRegs, #CostEntries, IndexToCostTbl}\n";
638 OS << "static const llvm::MCRegisterFileDesc " << ProcModel.ModelName
639 << "RegisterFiles"
640 << "[] = {\n"
641 << " { \"InvalidRegisterFile\", 0, 0, 0 },\n";
642 unsigned CostTblIndex = 0;
643
644 for (const CodeGenRegisterFile &RD : ProcModel.RegisterFiles) {
645 OS << " { ";
646 OS << '"' << RD.Name << '"' << ", " << RD.NumPhysRegs << ", ";
647 unsigned NumCostEntries = RD.Costs.size();
648 OS << NumCostEntries << ", " << CostTblIndex << "},\n";
649 CostTblIndex += NumCostEntries;
650 }
651 OS << "};\n";
652
653 // Now generate a table for the extra processor info.
654 OS << "\nstatic const llvm::MCExtraProcessorInfo " << ProcModel.ModelName
655 << "ExtraInfo = {\n " << ProcModel.ModelName << "RegisterFiles,\n "
656 << (1 + ProcModel.RegisterFiles.size())
657 << ", // Number of register files.\n "
658 << ProcModel.ModelName << "RegisterCosts,\n " << CostTblIndex
659 << " // Number of register cost entries.\n"
660 << "};\n";
661}
662
Andrew Trick23f3c652012-09-17 22:18:45 +0000663void SubtargetEmitter::EmitProcessorResources(const CodeGenProcModel &ProcModel,
664 raw_ostream &OS) {
Clement Courbet39911e22018-02-08 08:46:48 +0000665 EmitProcessorResourceSubUnits(ProcModel, OS);
666
667 OS << "\n// {Name, NumUnits, SuperIdx, IsBuffered, SubUnitsIdxBegin}\n";
David Blaikiee6503d82018-02-08 19:57:05 +0000668 OS << "static const llvm::MCProcResourceDesc " << ProcModel.ModelName
669 << "ProcResources"
670 << "[] = {\n"
Andrea Di Biagio30e94022018-03-08 10:38:45 +0000671 << " {\"InvalidUnit\", 0, 0, 0, 0},\n";
Andrew Trick23f3c652012-09-17 22:18:45 +0000672
Clement Courbet39911e22018-02-08 08:46:48 +0000673 unsigned SubUnitsOffset = 1;
Andrew Trick23f3c652012-09-17 22:18:45 +0000674 for (unsigned i = 0, e = ProcModel.ProcResourceDefs.size(); i < e; ++i) {
675 Record *PRDef = ProcModel.ProcResourceDefs[i];
676
Craig Topper24064772014-04-15 07:20:03 +0000677 Record *SuperDef = nullptr;
Andrew Trick4e67cba2013-03-14 21:21:50 +0000678 unsigned SuperIdx = 0;
679 unsigned NumUnits = 0;
Clement Courbet39911e22018-02-08 08:46:48 +0000680 const unsigned SubUnitsBeginOffset = SubUnitsOffset;
Andrew Trick40c4f382013-06-15 04:50:06 +0000681 int BufferSize = PRDef->getValueAsInt("BufferSize");
Andrew Trick4e67cba2013-03-14 21:21:50 +0000682 if (PRDef->isSubClassOf("ProcResGroup")) {
683 RecVec ResUnits = PRDef->getValueAsListOfDefs("Resources");
Craig Topper29c55dcb2016-02-13 06:03:32 +0000684 for (Record *RU : ResUnits) {
685 NumUnits += RU->getValueAsInt("NumUnits");
Clement Courbet873aa112018-02-09 10:28:46 +0000686 SubUnitsOffset += RU->getValueAsInt("NumUnits");
Andrew Trick4e67cba2013-03-14 21:21:50 +0000687 }
688 }
689 else {
690 // Find the SuperIdx
691 if (PRDef->getValueInit("Super")->isComplete()) {
Evandro Menezes9dc54e22017-11-21 21:33:52 +0000692 SuperDef =
693 SchedModels.findProcResUnits(PRDef->getValueAsDef("Super"),
694 ProcModel, PRDef->getLoc());
Andrew Trick4e67cba2013-03-14 21:21:50 +0000695 SuperIdx = ProcModel.getProcResourceIdx(SuperDef);
696 }
Andrew Tricka5c747b2013-03-14 22:47:01 +0000697 NumUnits = PRDef->getValueAsInt("NumUnits");
Andrew Trick23f3c652012-09-17 22:18:45 +0000698 }
699 // Emit the ProcResourceDesc
Andrea Di Biagio30e94022018-03-08 10:38:45 +0000700 OS << " {\"" << PRDef->getName() << "\", ";
Andrew Trick23f3c652012-09-17 22:18:45 +0000701 if (PRDef->getName().size() < 15)
702 OS.indent(15 - PRDef->getName().size());
Clement Courbet39911e22018-02-08 08:46:48 +0000703 OS << NumUnits << ", " << SuperIdx << ", " << BufferSize << ", ";
704 if (SubUnitsBeginOffset != SubUnitsOffset) {
705 OS << ProcModel.ModelName << "ProcResourceSubUnits + "
706 << SubUnitsBeginOffset;
707 } else {
708 OS << "nullptr";
709 }
710 OS << "}, // #" << i+1;
Andrew Trick23f3c652012-09-17 22:18:45 +0000711 if (SuperDef)
712 OS << ", Super=" << SuperDef->getName();
713 OS << "\n";
714 }
715 OS << "};\n";
716}
717
Andrew Trick9ef08822012-09-17 22:18:48 +0000718// Find the WriteRes Record that defines processor resources for this
719// SchedWrite.
720Record *SubtargetEmitter::FindWriteResources(
Andrew Trick9257b8f2012-09-22 02:24:21 +0000721 const CodeGenSchedRW &SchedWrite, const CodeGenProcModel &ProcModel) {
Andrew Trick9ef08822012-09-17 22:18:48 +0000722
723 // Check if the SchedWrite is already subtarget-specific and directly
724 // specifies a set of processor resources.
Andrew Trick9257b8f2012-09-22 02:24:21 +0000725 if (SchedWrite.TheDef->isSubClassOf("SchedWriteRes"))
726 return SchedWrite.TheDef;
727
Craig Topper24064772014-04-15 07:20:03 +0000728 Record *AliasDef = nullptr;
Craig Topper29c55dcb2016-02-13 06:03:32 +0000729 for (Record *A : SchedWrite.Aliases) {
Andrew Trick9257b8f2012-09-22 02:24:21 +0000730 const CodeGenSchedRW &AliasRW =
Craig Topper29c55dcb2016-02-13 06:03:32 +0000731 SchedModels.getSchedRW(A->getValueAsDef("AliasRW"));
Andrew Trickda984b12012-10-03 23:06:28 +0000732 if (AliasRW.TheDef->getValueInit("SchedModel")->isComplete()) {
733 Record *ModelDef = AliasRW.TheDef->getValueAsDef("SchedModel");
734 if (&SchedModels.getProcModel(ModelDef) != &ProcModel)
735 continue;
736 }
Andrew Trick9257b8f2012-09-22 02:24:21 +0000737 if (AliasDef)
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000738 PrintFatalError(AliasRW.TheDef->getLoc(), "Multiple aliases "
Andrew Trick9257b8f2012-09-22 02:24:21 +0000739 "defined for processor " + ProcModel.ModelName +
740 " Ensure only one SchedAlias exists per RW.");
741 AliasDef = AliasRW.TheDef;
742 }
743 if (AliasDef && AliasDef->isSubClassOf("SchedWriteRes"))
744 return AliasDef;
Andrew Trick9ef08822012-09-17 22:18:48 +0000745
746 // Check this processor's list of write resources.
Craig Topper24064772014-04-15 07:20:03 +0000747 Record *ResDef = nullptr;
Craig Topper29c55dcb2016-02-13 06:03:32 +0000748 for (Record *WR : ProcModel.WriteResDefs) {
749 if (!WR->isSubClassOf("WriteRes"))
Andrew Trick9ef08822012-09-17 22:18:48 +0000750 continue;
Craig Topper29c55dcb2016-02-13 06:03:32 +0000751 if (AliasDef == WR->getValueAsDef("WriteType")
752 || SchedWrite.TheDef == WR->getValueAsDef("WriteType")) {
Andrew Trick9257b8f2012-09-22 02:24:21 +0000753 if (ResDef) {
Craig Topper29c55dcb2016-02-13 06:03:32 +0000754 PrintFatalError(WR->getLoc(), "Resources are defined for both "
Andrew Trick9257b8f2012-09-22 02:24:21 +0000755 "SchedWrite and its alias on processor " +
756 ProcModel.ModelName);
757 }
Craig Topper29c55dcb2016-02-13 06:03:32 +0000758 ResDef = WR;
Andrew Trick9257b8f2012-09-22 02:24:21 +0000759 }
Andrew Trick9ef08822012-09-17 22:18:48 +0000760 }
Andrew Trick9257b8f2012-09-22 02:24:21 +0000761 // TODO: If ProcModel has a base model (previous generation processor),
762 // then call FindWriteResources recursively with that model here.
763 if (!ResDef) {
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000764 PrintFatalError(ProcModel.ModelDef->getLoc(),
Craig Topper01ebd9b2017-10-26 20:49:36 +0000765 Twine("Processor does not define resources for ") +
766 SchedWrite.TheDef->getName());
Andrew Trick9257b8f2012-09-22 02:24:21 +0000767 }
768 return ResDef;
Andrew Trick9ef08822012-09-17 22:18:48 +0000769}
770
771/// Find the ReadAdvance record for the given SchedRead on this processor or
772/// return NULL.
Andrew Trick9257b8f2012-09-22 02:24:21 +0000773Record *SubtargetEmitter::FindReadAdvance(const CodeGenSchedRW &SchedRead,
Andrew Trick9ef08822012-09-17 22:18:48 +0000774 const CodeGenProcModel &ProcModel) {
775 // Check for SchedReads that directly specify a ReadAdvance.
Andrew Trick9257b8f2012-09-22 02:24:21 +0000776 if (SchedRead.TheDef->isSubClassOf("SchedReadAdvance"))
777 return SchedRead.TheDef;
778
779 // Check this processor's list of aliases for SchedRead.
Craig Topper24064772014-04-15 07:20:03 +0000780 Record *AliasDef = nullptr;
Craig Topper29c55dcb2016-02-13 06:03:32 +0000781 for (Record *A : SchedRead.Aliases) {
Andrew Trick9257b8f2012-09-22 02:24:21 +0000782 const CodeGenSchedRW &AliasRW =
Craig Topper29c55dcb2016-02-13 06:03:32 +0000783 SchedModels.getSchedRW(A->getValueAsDef("AliasRW"));
Andrew Trickda984b12012-10-03 23:06:28 +0000784 if (AliasRW.TheDef->getValueInit("SchedModel")->isComplete()) {
785 Record *ModelDef = AliasRW.TheDef->getValueAsDef("SchedModel");
786 if (&SchedModels.getProcModel(ModelDef) != &ProcModel)
787 continue;
788 }
Andrew Trick9257b8f2012-09-22 02:24:21 +0000789 if (AliasDef)
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000790 PrintFatalError(AliasRW.TheDef->getLoc(), "Multiple aliases "
Andrew Trick9257b8f2012-09-22 02:24:21 +0000791 "defined for processor " + ProcModel.ModelName +
792 " Ensure only one SchedAlias exists per RW.");
793 AliasDef = AliasRW.TheDef;
794 }
795 if (AliasDef && AliasDef->isSubClassOf("SchedReadAdvance"))
796 return AliasDef;
Andrew Trick9ef08822012-09-17 22:18:48 +0000797
798 // Check this processor's ReadAdvanceList.
Craig Topper24064772014-04-15 07:20:03 +0000799 Record *ResDef = nullptr;
Craig Topper29c55dcb2016-02-13 06:03:32 +0000800 for (Record *RA : ProcModel.ReadAdvanceDefs) {
801 if (!RA->isSubClassOf("ReadAdvance"))
Andrew Trick9ef08822012-09-17 22:18:48 +0000802 continue;
Craig Topper29c55dcb2016-02-13 06:03:32 +0000803 if (AliasDef == RA->getValueAsDef("ReadType")
804 || SchedRead.TheDef == RA->getValueAsDef("ReadType")) {
Andrew Trick9257b8f2012-09-22 02:24:21 +0000805 if (ResDef) {
Craig Topper29c55dcb2016-02-13 06:03:32 +0000806 PrintFatalError(RA->getLoc(), "Resources are defined for both "
Andrew Trick9257b8f2012-09-22 02:24:21 +0000807 "SchedRead and its alias on processor " +
808 ProcModel.ModelName);
809 }
Craig Topper29c55dcb2016-02-13 06:03:32 +0000810 ResDef = RA;
Andrew Trick9257b8f2012-09-22 02:24:21 +0000811 }
Andrew Trick9ef08822012-09-17 22:18:48 +0000812 }
Andrew Trick9257b8f2012-09-22 02:24:21 +0000813 // TODO: If ProcModel has a base model (previous generation processor),
814 // then call FindReadAdvance recursively with that model here.
815 if (!ResDef && SchedRead.TheDef->getName() != "ReadDefault") {
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000816 PrintFatalError(ProcModel.ModelDef->getLoc(),
Craig Topper01ebd9b2017-10-26 20:49:36 +0000817 Twine("Processor does not define resources for ") +
818 SchedRead.TheDef->getName());
Andrew Trick9ef08822012-09-17 22:18:48 +0000819 }
Andrew Trick9257b8f2012-09-22 02:24:21 +0000820 return ResDef;
Andrew Trick9ef08822012-09-17 22:18:48 +0000821}
822
Andrew Trick4e67cba2013-03-14 21:21:50 +0000823// Expand an explicit list of processor resources into a full list of implied
Andrew Tricka3801a32013-04-23 23:45:16 +0000824// resource groups and super resources that cover them.
Andrew Trick4e67cba2013-03-14 21:21:50 +0000825void SubtargetEmitter::ExpandProcResources(RecVec &PRVec,
826 std::vector<int64_t> &Cycles,
Andrew Tricka3801a32013-04-23 23:45:16 +0000827 const CodeGenProcModel &PM) {
Andrew Trick4e67cba2013-03-14 21:21:50 +0000828 // Default to 1 resource cycle.
829 Cycles.resize(PRVec.size(), 1);
830 for (unsigned i = 0, e = PRVec.size(); i != e; ++i) {
Andrew Tricka3801a32013-04-23 23:45:16 +0000831 Record *PRDef = PRVec[i];
Andrew Trick4e67cba2013-03-14 21:21:50 +0000832 RecVec SubResources;
Andrew Tricka3801a32013-04-23 23:45:16 +0000833 if (PRDef->isSubClassOf("ProcResGroup"))
834 SubResources = PRDef->getValueAsListOfDefs("Resources");
Andrew Trick4e67cba2013-03-14 21:21:50 +0000835 else {
Andrew Tricka3801a32013-04-23 23:45:16 +0000836 SubResources.push_back(PRDef);
Evandro Menezes9dc54e22017-11-21 21:33:52 +0000837 PRDef = SchedModels.findProcResUnits(PRDef, PM, PRDef->getLoc());
Andrew Tricka3801a32013-04-23 23:45:16 +0000838 for (Record *SubDef = PRDef;
839 SubDef->getValueInit("Super")->isComplete();) {
840 if (SubDef->isSubClassOf("ProcResGroup")) {
841 // Disallow this for simplicitly.
842 PrintFatalError(SubDef->getLoc(), "Processor resource group "
843 " cannot be a super resources.");
844 }
845 Record *SuperDef =
Evandro Menezes9dc54e22017-11-21 21:33:52 +0000846 SchedModels.findProcResUnits(SubDef->getValueAsDef("Super"), PM,
847 SubDef->getLoc());
Andrew Tricka3801a32013-04-23 23:45:16 +0000848 PRVec.push_back(SuperDef);
849 Cycles.push_back(Cycles[i]);
850 SubDef = SuperDef;
851 }
Andrew Trick4e67cba2013-03-14 21:21:50 +0000852 }
Craig Topper29c55dcb2016-02-13 06:03:32 +0000853 for (Record *PR : PM.ProcResourceDefs) {
854 if (PR == PRDef || !PR->isSubClassOf("ProcResGroup"))
Andrew Trick4e67cba2013-03-14 21:21:50 +0000855 continue;
Craig Topper29c55dcb2016-02-13 06:03:32 +0000856 RecVec SuperResources = PR->getValueAsListOfDefs("Resources");
Andrew Trick4e67cba2013-03-14 21:21:50 +0000857 RecIter SubI = SubResources.begin(), SubE = SubResources.end();
Andrew Trick6aa7a872013-04-23 23:45:11 +0000858 for( ; SubI != SubE; ++SubI) {
David Majnemer0d955d02016-08-11 22:21:41 +0000859 if (!is_contained(SuperResources, *SubI)) {
Andrew Trick4e67cba2013-03-14 21:21:50 +0000860 break;
Andrew Trick6aa7a872013-04-23 23:45:11 +0000861 }
Andrew Trick4e67cba2013-03-14 21:21:50 +0000862 }
863 if (SubI == SubE) {
Craig Topper29c55dcb2016-02-13 06:03:32 +0000864 PRVec.push_back(PR);
Andrew Trick4e67cba2013-03-14 21:21:50 +0000865 Cycles.push_back(Cycles[i]);
866 }
867 }
868 }
869}
870
Andrew Trick9ef08822012-09-17 22:18:48 +0000871// Generate the SchedClass table for this processor and update global
872// tables. Must be called for each processor in order.
873void SubtargetEmitter::GenSchedClassTables(const CodeGenProcModel &ProcModel,
874 SchedClassTables &SchedTables) {
875 SchedTables.ProcSchedClasses.resize(SchedTables.ProcSchedClasses.size() + 1);
876 if (!ProcModel.hasInstrSchedModel())
877 return;
878
879 std::vector<MCSchedClassDesc> &SCTab = SchedTables.ProcSchedClasses.back();
Joel Jones80372332017-06-28 00:06:40 +0000880 DEBUG(dbgs() << "\n+++ SCHED CLASSES (GenSchedClassTables) +++\n");
Craig Topper29c55dcb2016-02-13 06:03:32 +0000881 for (const CodeGenSchedClass &SC : SchedModels.schedClasses()) {
882 DEBUG(SC.dump(&SchedModels));
Andrew Trick7aba6be2012-10-03 23:06:25 +0000883
Andrew Trick9ef08822012-09-17 22:18:48 +0000884 SCTab.resize(SCTab.size() + 1);
885 MCSchedClassDesc &SCDesc = SCTab.back();
Andrew Trickab722bd2012-09-18 03:18:56 +0000886 // SCDesc.Name is guarded by NDEBUG
Andrew Trick9ef08822012-09-17 22:18:48 +0000887 SCDesc.NumMicroOps = 0;
888 SCDesc.BeginGroup = false;
889 SCDesc.EndGroup = false;
890 SCDesc.WriteProcResIdx = 0;
891 SCDesc.WriteLatencyIdx = 0;
892 SCDesc.ReadAdvanceIdx = 0;
893
894 // A Variant SchedClass has no resources of its own.
Andrew Tricke97978f2013-03-26 21:36:39 +0000895 bool HasVariants = false;
Javed Absar32e3cb72017-10-06 15:25:04 +0000896 for (const CodeGenSchedTransition &CGT :
897 make_range(SC.Transitions.begin(), SC.Transitions.end())) {
898 if (CGT.ProcIndices[0] == 0 ||
899 is_contained(CGT.ProcIndices, ProcModel.Index)) {
Andrew Tricke97978f2013-03-26 21:36:39 +0000900 HasVariants = true;
901 break;
902 }
903 }
904 if (HasVariants) {
Andrew Trick9ef08822012-09-17 22:18:48 +0000905 SCDesc.NumMicroOps = MCSchedClassDesc::VariantNumMicroOps;
906 continue;
907 }
908
909 // Determine if the SchedClass is actually reachable on this processor. If
910 // not don't try to locate the processor resources, it will fail.
911 // If ProcIndices contains 0, this class applies to all processors.
Craig Topper29c55dcb2016-02-13 06:03:32 +0000912 assert(!SC.ProcIndices.empty() && "expect at least one procidx");
913 if (SC.ProcIndices[0] != 0) {
David Majnemer42531262016-08-12 03:55:06 +0000914 if (!is_contained(SC.ProcIndices, ProcModel.Index))
Andrew Trick9ef08822012-09-17 22:18:48 +0000915 continue;
916 }
Craig Topper29c55dcb2016-02-13 06:03:32 +0000917 IdxVec Writes = SC.Writes;
918 IdxVec Reads = SC.Reads;
919 if (!SC.InstRWs.empty()) {
Sylvestre Ledru543f15b2018-03-17 17:30:08 +0000920 // This class has a default ReadWrite list which can be overridden by
Andrew Trick7aba6be2012-10-03 23:06:25 +0000921 // InstRW definitions.
Craig Topper24064772014-04-15 07:20:03 +0000922 Record *RWDef = nullptr;
Craig Topper29c55dcb2016-02-13 06:03:32 +0000923 for (Record *RW : SC.InstRWs) {
924 Record *RWModelDef = RW->getValueAsDef("SchedModel");
Andrew Trick9ef08822012-09-17 22:18:48 +0000925 if (&ProcModel == &SchedModels.getProcModel(RWModelDef)) {
Craig Topper29c55dcb2016-02-13 06:03:32 +0000926 RWDef = RW;
Andrew Trick9ef08822012-09-17 22:18:48 +0000927 break;
928 }
929 }
930 if (RWDef) {
Andrew Trickda984b12012-10-03 23:06:28 +0000931 Writes.clear();
932 Reads.clear();
Andrew Trick9ef08822012-09-17 22:18:48 +0000933 SchedModels.findRWs(RWDef->getValueAsListOfDefs("OperandReadWrites"),
934 Writes, Reads);
935 }
936 }
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000937 if (Writes.empty()) {
938 // Check this processor's itinerary class resources.
Craig Topper29c55dcb2016-02-13 06:03:32 +0000939 for (Record *I : ProcModel.ItinRWDefs) {
940 RecVec Matched = I->getValueAsListOfDefs("MatchedItinClasses");
David Majnemer0d955d02016-08-11 22:21:41 +0000941 if (is_contained(Matched, SC.ItinClassDef)) {
Craig Topper29c55dcb2016-02-13 06:03:32 +0000942 SchedModels.findRWs(I->getValueAsListOfDefs("OperandReadWrites"),
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000943 Writes, Reads);
944 break;
945 }
946 }
947 if (Writes.empty()) {
948 DEBUG(dbgs() << ProcModel.ModelName
Craig Topper29c55dcb2016-02-13 06:03:32 +0000949 << " does not have resources for class " << SC.Name << '\n');
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000950 }
951 }
Andrew Trick9ef08822012-09-17 22:18:48 +0000952 // Sum resources across all operand writes.
953 std::vector<MCWriteProcResEntry> WriteProcResources;
954 std::vector<MCWriteLatencyEntry> WriteLatencies;
Andrew Trickcfe222c2012-09-19 04:43:19 +0000955 std::vector<std::string> WriterNames;
Andrew Trick9ef08822012-09-17 22:18:48 +0000956 std::vector<MCReadAdvanceEntry> ReadAdvanceEntries;
Craig Topper29c55dcb2016-02-13 06:03:32 +0000957 for (unsigned W : Writes) {
Andrew Trick9ef08822012-09-17 22:18:48 +0000958 IdxVec WriteSeq;
Craig Topper29c55dcb2016-02-13 06:03:32 +0000959 SchedModels.expandRWSeqForProc(W, WriteSeq, /*IsRead=*/false,
Andrew Trickda984b12012-10-03 23:06:28 +0000960 ProcModel);
Andrew Trick9ef08822012-09-17 22:18:48 +0000961
962 // For each operand, create a latency entry.
963 MCWriteLatencyEntry WLEntry;
964 WLEntry.Cycles = 0;
Andrew Trickcfe222c2012-09-19 04:43:19 +0000965 unsigned WriteID = WriteSeq.back();
966 WriterNames.push_back(SchedModels.getSchedWrite(WriteID).Name);
967 // If this Write is not referenced by a ReadAdvance, don't distinguish it
968 // from other WriteLatency entries.
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000969 if (!SchedModels.hasReadOfWrite(
970 SchedModels.getSchedWrite(WriteID).TheDef)) {
Andrew Trickcfe222c2012-09-19 04:43:19 +0000971 WriteID = 0;
972 }
973 WLEntry.WriteResourceID = WriteID;
Andrew Trick9ef08822012-09-17 22:18:48 +0000974
Craig Topper29c55dcb2016-02-13 06:03:32 +0000975 for (unsigned WS : WriteSeq) {
Andrew Trick9ef08822012-09-17 22:18:48 +0000976
Andrew Trick9257b8f2012-09-22 02:24:21 +0000977 Record *WriteRes =
Craig Topper29c55dcb2016-02-13 06:03:32 +0000978 FindWriteResources(SchedModels.getSchedWrite(WS), ProcModel);
Andrew Trick9ef08822012-09-17 22:18:48 +0000979
980 // Mark the parent class as invalid for unsupported write types.
981 if (WriteRes->getValueAsBit("Unsupported")) {
982 SCDesc.NumMicroOps = MCSchedClassDesc::InvalidNumMicroOps;
983 break;
984 }
985 WLEntry.Cycles += WriteRes->getValueAsInt("Latency");
986 SCDesc.NumMicroOps += WriteRes->getValueAsInt("NumMicroOps");
987 SCDesc.BeginGroup |= WriteRes->getValueAsBit("BeginGroup");
988 SCDesc.EndGroup |= WriteRes->getValueAsBit("EndGroup");
Javed Absar3d594372017-03-27 20:46:37 +0000989 SCDesc.BeginGroup |= WriteRes->getValueAsBit("SingleIssue");
990 SCDesc.EndGroup |= WriteRes->getValueAsBit("SingleIssue");
Andrew Trick9ef08822012-09-17 22:18:48 +0000991
992 // Create an entry for each ProcResource listed in WriteRes.
993 RecVec PRVec = WriteRes->getValueAsListOfDefs("ProcResources");
994 std::vector<int64_t> Cycles =
995 WriteRes->getValueAsListOfInts("ResourceCycles");
Andrew Trick4e67cba2013-03-14 21:21:50 +0000996
997 ExpandProcResources(PRVec, Cycles, ProcModel);
998
Andrew Trick9ef08822012-09-17 22:18:48 +0000999 for (unsigned PRIdx = 0, PREnd = PRVec.size();
1000 PRIdx != PREnd; ++PRIdx) {
1001 MCWriteProcResEntry WPREntry;
1002 WPREntry.ProcResourceIdx = ProcModel.getProcResourceIdx(PRVec[PRIdx]);
1003 assert(WPREntry.ProcResourceIdx && "Bad ProcResourceIdx");
Andrew Trick4e67cba2013-03-14 21:21:50 +00001004 WPREntry.Cycles = Cycles[PRIdx];
Andrew Trick3821d9d2013-03-01 23:31:26 +00001005 // If this resource is already used in this sequence, add the current
1006 // entry's cycles so that the same resource appears to be used
1007 // serially, rather than multiple parallel uses. This is important for
1008 // in-order machine where the resource consumption is a hazard.
1009 unsigned WPRIdx = 0, WPREnd = WriteProcResources.size();
1010 for( ; WPRIdx != WPREnd; ++WPRIdx) {
1011 if (WriteProcResources[WPRIdx].ProcResourceIdx
1012 == WPREntry.ProcResourceIdx) {
1013 WriteProcResources[WPRIdx].Cycles += WPREntry.Cycles;
1014 break;
1015 }
1016 }
1017 if (WPRIdx == WPREnd)
1018 WriteProcResources.push_back(WPREntry);
Andrew Trick9ef08822012-09-17 22:18:48 +00001019 }
1020 }
1021 WriteLatencies.push_back(WLEntry);
1022 }
1023 // Create an entry for each operand Read in this SchedClass.
1024 // Entries must be sorted first by UseIdx then by WriteResourceID.
1025 for (unsigned UseIdx = 0, EndIdx = Reads.size();
1026 UseIdx != EndIdx; ++UseIdx) {
Andrew Trick9257b8f2012-09-22 02:24:21 +00001027 Record *ReadAdvance =
1028 FindReadAdvance(SchedModels.getSchedRead(Reads[UseIdx]), ProcModel);
Andrew Trick9ef08822012-09-17 22:18:48 +00001029 if (!ReadAdvance)
1030 continue;
1031
1032 // Mark the parent class as invalid for unsupported write types.
1033 if (ReadAdvance->getValueAsBit("Unsupported")) {
1034 SCDesc.NumMicroOps = MCSchedClassDesc::InvalidNumMicroOps;
1035 break;
1036 }
1037 RecVec ValidWrites = ReadAdvance->getValueAsListOfDefs("ValidWrites");
1038 IdxVec WriteIDs;
1039 if (ValidWrites.empty())
1040 WriteIDs.push_back(0);
1041 else {
Craig Topper29c55dcb2016-02-13 06:03:32 +00001042 for (Record *VW : ValidWrites) {
1043 WriteIDs.push_back(SchedModels.getSchedRWIdx(VW, /*IsRead=*/false));
Andrew Trick9ef08822012-09-17 22:18:48 +00001044 }
1045 }
1046 std::sort(WriteIDs.begin(), WriteIDs.end());
Craig Topper29c55dcb2016-02-13 06:03:32 +00001047 for(unsigned W : WriteIDs) {
Andrew Trick9ef08822012-09-17 22:18:48 +00001048 MCReadAdvanceEntry RAEntry;
1049 RAEntry.UseIdx = UseIdx;
Craig Topper29c55dcb2016-02-13 06:03:32 +00001050 RAEntry.WriteResourceID = W;
Andrew Trick9ef08822012-09-17 22:18:48 +00001051 RAEntry.Cycles = ReadAdvance->getValueAsInt("Cycles");
1052 ReadAdvanceEntries.push_back(RAEntry);
1053 }
1054 }
1055 if (SCDesc.NumMicroOps == MCSchedClassDesc::InvalidNumMicroOps) {
1056 WriteProcResources.clear();
1057 WriteLatencies.clear();
1058 ReadAdvanceEntries.clear();
1059 }
1060 // Add the information for this SchedClass to the global tables using basic
1061 // compression.
1062 //
1063 // WritePrecRes entries are sorted by ProcResIdx.
1064 std::sort(WriteProcResources.begin(), WriteProcResources.end(),
1065 LessWriteProcResources());
1066
1067 SCDesc.NumWriteProcResEntries = WriteProcResources.size();
1068 std::vector<MCWriteProcResEntry>::iterator WPRPos =
1069 std::search(SchedTables.WriteProcResources.begin(),
1070 SchedTables.WriteProcResources.end(),
1071 WriteProcResources.begin(), WriteProcResources.end());
1072 if (WPRPos != SchedTables.WriteProcResources.end())
1073 SCDesc.WriteProcResIdx = WPRPos - SchedTables.WriteProcResources.begin();
1074 else {
1075 SCDesc.WriteProcResIdx = SchedTables.WriteProcResources.size();
1076 SchedTables.WriteProcResources.insert(WPRPos, WriteProcResources.begin(),
1077 WriteProcResources.end());
1078 }
1079 // Latency entries must remain in operand order.
1080 SCDesc.NumWriteLatencyEntries = WriteLatencies.size();
1081 std::vector<MCWriteLatencyEntry>::iterator WLPos =
1082 std::search(SchedTables.WriteLatencies.begin(),
1083 SchedTables.WriteLatencies.end(),
1084 WriteLatencies.begin(), WriteLatencies.end());
Andrew Trickcfe222c2012-09-19 04:43:19 +00001085 if (WLPos != SchedTables.WriteLatencies.end()) {
1086 unsigned idx = WLPos - SchedTables.WriteLatencies.begin();
1087 SCDesc.WriteLatencyIdx = idx;
1088 for (unsigned i = 0, e = WriteLatencies.size(); i < e; ++i)
1089 if (SchedTables.WriterNames[idx + i].find(WriterNames[i]) ==
1090 std::string::npos) {
1091 SchedTables.WriterNames[idx + i] += std::string("_") + WriterNames[i];
1092 }
1093 }
Andrew Trick9ef08822012-09-17 22:18:48 +00001094 else {
1095 SCDesc.WriteLatencyIdx = SchedTables.WriteLatencies.size();
Andrew Trickcfe222c2012-09-19 04:43:19 +00001096 SchedTables.WriteLatencies.insert(SchedTables.WriteLatencies.end(),
1097 WriteLatencies.begin(),
1098 WriteLatencies.end());
1099 SchedTables.WriterNames.insert(SchedTables.WriterNames.end(),
1100 WriterNames.begin(), WriterNames.end());
Andrew Trick9ef08822012-09-17 22:18:48 +00001101 }
1102 // ReadAdvanceEntries must remain in operand order.
1103 SCDesc.NumReadAdvanceEntries = ReadAdvanceEntries.size();
1104 std::vector<MCReadAdvanceEntry>::iterator RAPos =
1105 std::search(SchedTables.ReadAdvanceEntries.begin(),
1106 SchedTables.ReadAdvanceEntries.end(),
1107 ReadAdvanceEntries.begin(), ReadAdvanceEntries.end());
1108 if (RAPos != SchedTables.ReadAdvanceEntries.end())
1109 SCDesc.ReadAdvanceIdx = RAPos - SchedTables.ReadAdvanceEntries.begin();
1110 else {
1111 SCDesc.ReadAdvanceIdx = SchedTables.ReadAdvanceEntries.size();
1112 SchedTables.ReadAdvanceEntries.insert(RAPos, ReadAdvanceEntries.begin(),
1113 ReadAdvanceEntries.end());
1114 }
1115 }
1116}
1117
Andrew Tricka72fca62012-09-17 22:18:50 +00001118// Emit SchedClass tables for all processors and associated global tables.
1119void SubtargetEmitter::EmitSchedClassTables(SchedClassTables &SchedTables,
1120 raw_ostream &OS) {
1121 // Emit global WriteProcResTable.
1122 OS << "\n// {ProcResourceIdx, Cycles}\n"
1123 << "extern const llvm::MCWriteProcResEntry "
1124 << Target << "WriteProcResTable[] = {\n"
1125 << " { 0, 0}, // Invalid\n";
1126 for (unsigned WPRIdx = 1, WPREnd = SchedTables.WriteProcResources.size();
1127 WPRIdx != WPREnd; ++WPRIdx) {
1128 MCWriteProcResEntry &WPREntry = SchedTables.WriteProcResources[WPRIdx];
1129 OS << " {" << format("%2d", WPREntry.ProcResourceIdx) << ", "
1130 << format("%2d", WPREntry.Cycles) << "}";
1131 if (WPRIdx + 1 < WPREnd)
1132 OS << ',';
1133 OS << " // #" << WPRIdx << '\n';
1134 }
1135 OS << "}; // " << Target << "WriteProcResTable\n";
1136
1137 // Emit global WriteLatencyTable.
1138 OS << "\n// {Cycles, WriteResourceID}\n"
1139 << "extern const llvm::MCWriteLatencyEntry "
1140 << Target << "WriteLatencyTable[] = {\n"
1141 << " { 0, 0}, // Invalid\n";
1142 for (unsigned WLIdx = 1, WLEnd = SchedTables.WriteLatencies.size();
1143 WLIdx != WLEnd; ++WLIdx) {
1144 MCWriteLatencyEntry &WLEntry = SchedTables.WriteLatencies[WLIdx];
1145 OS << " {" << format("%2d", WLEntry.Cycles) << ", "
1146 << format("%2d", WLEntry.WriteResourceID) << "}";
1147 if (WLIdx + 1 < WLEnd)
1148 OS << ',';
Andrew Trickcfe222c2012-09-19 04:43:19 +00001149 OS << " // #" << WLIdx << " " << SchedTables.WriterNames[WLIdx] << '\n';
Andrew Tricka72fca62012-09-17 22:18:50 +00001150 }
1151 OS << "}; // " << Target << "WriteLatencyTable\n";
1152
1153 // Emit global ReadAdvanceTable.
1154 OS << "\n// {UseIdx, WriteResourceID, Cycles}\n"
1155 << "extern const llvm::MCReadAdvanceEntry "
1156 << Target << "ReadAdvanceTable[] = {\n"
1157 << " {0, 0, 0}, // Invalid\n";
1158 for (unsigned RAIdx = 1, RAEnd = SchedTables.ReadAdvanceEntries.size();
1159 RAIdx != RAEnd; ++RAIdx) {
1160 MCReadAdvanceEntry &RAEntry = SchedTables.ReadAdvanceEntries[RAIdx];
1161 OS << " {" << RAEntry.UseIdx << ", "
1162 << format("%2d", RAEntry.WriteResourceID) << ", "
1163 << format("%2d", RAEntry.Cycles) << "}";
1164 if (RAIdx + 1 < RAEnd)
1165 OS << ',';
1166 OS << " // #" << RAIdx << '\n';
1167 }
1168 OS << "}; // " << Target << "ReadAdvanceTable\n";
1169
1170 // Emit a SchedClass table for each processor.
1171 for (CodeGenSchedModels::ProcIter PI = SchedModels.procModelBegin(),
1172 PE = SchedModels.procModelEnd(); PI != PE; ++PI) {
1173 if (!PI->hasInstrSchedModel())
1174 continue;
1175
1176 std::vector<MCSchedClassDesc> &SCTab =
Rafael Espindola72961392012-11-02 20:57:36 +00001177 SchedTables.ProcSchedClasses[1 + (PI - SchedModels.procModelBegin())];
Andrew Tricka72fca62012-09-17 22:18:50 +00001178
1179 OS << "\n// {Name, NumMicroOps, BeginGroup, EndGroup,"
1180 << " WriteProcResIdx,#, WriteLatencyIdx,#, ReadAdvanceIdx,#}\n";
1181 OS << "static const llvm::MCSchedClassDesc "
1182 << PI->ModelName << "SchedClasses[] = {\n";
1183
1184 // The first class is always invalid. We no way to distinguish it except by
1185 // name and position.
Andrew Trickbf8a28d2013-03-16 18:58:55 +00001186 assert(SchedModels.getSchedClass(0).Name == "NoInstrModel"
Andrew Tricka72fca62012-09-17 22:18:50 +00001187 && "invalid class not first");
1188 OS << " {DBGFIELD(\"InvalidSchedClass\") "
1189 << MCSchedClassDesc::InvalidNumMicroOps
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001190 << ", false, false, 0, 0, 0, 0, 0, 0},\n";
Andrew Tricka72fca62012-09-17 22:18:50 +00001191
1192 for (unsigned SCIdx = 1, SCEnd = SCTab.size(); SCIdx != SCEnd; ++SCIdx) {
1193 MCSchedClassDesc &MCDesc = SCTab[SCIdx];
1194 const CodeGenSchedClass &SchedClass = SchedModels.getSchedClass(SCIdx);
1195 OS << " {DBGFIELD(\"" << SchedClass.Name << "\") ";
1196 if (SchedClass.Name.size() < 18)
1197 OS.indent(18 - SchedClass.Name.size());
1198 OS << MCDesc.NumMicroOps
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001199 << ", " << ( MCDesc.BeginGroup ? "true" : "false" )
1200 << ", " << ( MCDesc.EndGroup ? "true" : "false" )
Andrew Tricka72fca62012-09-17 22:18:50 +00001201 << ", " << format("%2d", MCDesc.WriteProcResIdx)
1202 << ", " << MCDesc.NumWriteProcResEntries
1203 << ", " << format("%2d", MCDesc.WriteLatencyIdx)
1204 << ", " << MCDesc.NumWriteLatencyEntries
1205 << ", " << format("%2d", MCDesc.ReadAdvanceIdx)
Craig Topperdf1285b2017-10-24 15:50:53 +00001206 << ", " << MCDesc.NumReadAdvanceEntries
1207 << "}, // #" << SCIdx << '\n';
Andrew Tricka72fca62012-09-17 22:18:50 +00001208 }
1209 OS << "}; // " << PI->ModelName << "SchedClasses\n";
1210 }
1211}
1212
Andrew Trick87255e32012-07-07 04:00:00 +00001213void SubtargetEmitter::EmitProcessorModels(raw_ostream &OS) {
1214 // For each processor model.
Craig Topper29c55dcb2016-02-13 06:03:32 +00001215 for (const CodeGenProcModel &PM : SchedModels.procModels()) {
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +00001216 // Emit extra processor info if available.
1217 if (PM.hasExtraProcessorInfo())
1218 EmitExtraProcessorInfo(PM, OS);
Andrew Trick23f3c652012-09-17 22:18:45 +00001219 // Emit processor resource table.
Craig Topper29c55dcb2016-02-13 06:03:32 +00001220 if (PM.hasInstrSchedModel())
1221 EmitProcessorResources(PM, OS);
1222 else if(!PM.ProcResourceDefs.empty())
1223 PrintFatalError(PM.ModelDef->getLoc(), "SchedMachineModel defines "
Andrew Trick9ef08822012-09-17 22:18:48 +00001224 "ProcResources without defining WriteRes SchedWriteRes");
Andrew Trick23f3c652012-09-17 22:18:45 +00001225
Andrew Trick73d77362012-06-05 03:44:40 +00001226 // Begin processor itinerary properties
1227 OS << "\n";
Craig Topper29c55dcb2016-02-13 06:03:32 +00001228 OS << "static const llvm::MCSchedModel " << PM.ModelName << " = {\n";
1229 EmitProcessorProp(OS, PM.ModelDef, "IssueWidth", ',');
1230 EmitProcessorProp(OS, PM.ModelDef, "MicroOpBufferSize", ',');
1231 EmitProcessorProp(OS, PM.ModelDef, "LoopMicroOpBufferSize", ',');
1232 EmitProcessorProp(OS, PM.ModelDef, "LoadLatency", ',');
1233 EmitProcessorProp(OS, PM.ModelDef, "HighLatency", ',');
1234 EmitProcessorProp(OS, PM.ModelDef, "MispredictPenalty", ',');
Andrew Trickb6854d82013-09-25 18:14:12 +00001235
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001236 bool PostRAScheduler =
1237 (PM.ModelDef ? PM.ModelDef->getValueAsBit("PostRAScheduler") : false);
Sanjay Patela2f658d2014-07-15 22:39:58 +00001238
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001239 OS << " " << (PostRAScheduler ? "true" : "false") << ", // "
1240 << "PostRAScheduler\n";
1241
1242 bool CompleteModel =
1243 (PM.ModelDef ? PM.ModelDef->getValueAsBit("CompleteModel") : false);
1244
1245 OS << " " << (CompleteModel ? "true" : "false") << ", // "
1246 << "CompleteModel\n";
Andrew Trickb6854d82013-09-25 18:14:12 +00001247
Craig Topper29c55dcb2016-02-13 06:03:32 +00001248 OS << " " << PM.Index << ", // Processor ID\n";
1249 if (PM.hasInstrSchedModel())
1250 OS << " " << PM.ModelName << "ProcResources" << ",\n"
1251 << " " << PM.ModelName << "SchedClasses" << ",\n"
1252 << " " << PM.ProcResourceDefs.size()+1 << ",\n"
Andrew Trickab722bd2012-09-18 03:18:56 +00001253 << " " << (SchedModels.schedClassEnd()
1254 - SchedModels.schedClassBegin()) << ",\n";
1255 else
Hans Wennborg083ca9b2015-10-06 23:24:35 +00001256 OS << " nullptr, nullptr, 0, 0,"
1257 << " // No instruction-level machine model.\n";
Craig Topper29c55dcb2016-02-13 06:03:32 +00001258 if (PM.hasItineraries())
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +00001259 OS << " " << PM.ItinsDef->getName() << ",\n";
Andrew Trick9c302672012-06-22 03:58:51 +00001260 else
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +00001261 OS << " nullptr, // No Itinerary\n";
1262 if (PM.hasExtraProcessorInfo())
1263 OS << " &" << PM.ModelName << "ExtraInfo\n";
1264 else
1265 OS << " nullptr // No extra processor descriptor\n";
Craig Topper194cb742017-10-24 15:50:55 +00001266 OS << "};\n";
Jim Laskey86f002c2005-10-27 19:47:21 +00001267 }
Jim Laskey3763a502005-10-31 17:16:01 +00001268}
1269
1270//
1271// EmitProcessorLookup - generate cpu name to itinerary lookup table.
1272//
Daniel Dunbar38a22bf2009-07-03 00:10:29 +00001273void SubtargetEmitter::EmitProcessorLookup(raw_ostream &OS) {
Jim Laskey3763a502005-10-31 17:16:01 +00001274 // Gather and sort processor information
1275 std::vector<Record*> ProcessorList =
1276 Records.getAllDerivedDefinitions("Processor");
Duraid Madina018da4f2005-12-30 14:56:37 +00001277 std::sort(ProcessorList.begin(), ProcessorList.end(), LessRecordFieldName());
Jim Laskey3763a502005-10-31 17:16:01 +00001278
1279 // Begin processor table
1280 OS << "\n";
1281 OS << "// Sorted (by key) array of itineraries for CPU subtype.\n"
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00001282 << "extern const llvm::SubtargetInfoKV "
Andrew Trick87255e32012-07-07 04:00:00 +00001283 << Target << "ProcSchedKV[] = {\n";
Andrew Trickdb6ed642011-04-01 01:56:55 +00001284
Jim Laskey3763a502005-10-31 17:16:01 +00001285 // For each processor
Craig Topperdf1285b2017-10-24 15:50:53 +00001286 for (Record *Processor : ProcessorList) {
Craig Topperbcd3c372017-05-31 21:12:46 +00001287 StringRef Name = Processor->getValueAsString("Name");
Andrew Trick87255e32012-07-07 04:00:00 +00001288 const std::string &ProcModelName =
Andrew Trick76686492012-09-15 00:19:57 +00001289 SchedModels.getModelForProc(Processor).ModelName;
Andrew Trickdb6ed642011-04-01 01:56:55 +00001290
Jim Laskey3763a502005-10-31 17:16:01 +00001291 // Emit as { "cpu", procinit },
Craig Topperdf1285b2017-10-24 15:50:53 +00001292 OS << " { \"" << Name << "\", (const void *)&" << ProcModelName << " },\n";
Jim Laskey3763a502005-10-31 17:16:01 +00001293 }
Andrew Trickdb6ed642011-04-01 01:56:55 +00001294
Jim Laskey3763a502005-10-31 17:16:01 +00001295 // End processor table
1296 OS << "};\n";
Jim Laskey86f002c2005-10-27 19:47:21 +00001297}
1298
1299//
Andrew Trick87255e32012-07-07 04:00:00 +00001300// EmitSchedModel - Emits all scheduling model tables, folding common patterns.
Jim Laskey86f002c2005-10-27 19:47:21 +00001301//
Andrew Trick87255e32012-07-07 04:00:00 +00001302void SubtargetEmitter::EmitSchedModel(raw_ostream &OS) {
Andrew Trick23f3c652012-09-17 22:18:45 +00001303 OS << "#ifdef DBGFIELD\n"
1304 << "#error \"<target>GenSubtargetInfo.inc requires a DBGFIELD macro\"\n"
1305 << "#endif\n"
Aaron Ballman615eb472017-10-15 14:32:27 +00001306 << "#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)\n"
Andrew Trick23f3c652012-09-17 22:18:45 +00001307 << "#define DBGFIELD(x) x,\n"
1308 << "#else\n"
1309 << "#define DBGFIELD(x)\n"
1310 << "#endif\n";
1311
Andrew Trickbf8a28d2013-03-16 18:58:55 +00001312 if (SchedModels.hasItineraries()) {
Eugene Zelenko2bc2f332016-12-09 22:06:55 +00001313 std::vector<std::vector<InstrItinerary>> ProcItinLists;
Jim Laskey802748c2005-11-01 20:06:59 +00001314 // Emit the stage data
Andrew Trick87255e32012-07-07 04:00:00 +00001315 EmitStageAndOperandCycleData(OS, ProcItinLists);
1316 EmitItineraries(OS, ProcItinLists);
Jim Laskey802748c2005-11-01 20:06:59 +00001317 }
Andrew Tricka72fca62012-09-17 22:18:50 +00001318 OS << "\n// ===============================================================\n"
1319 << "// Data tables for the new per-operand machine model.\n";
Andrew Trick23f3c652012-09-17 22:18:45 +00001320
Andrew Trick9ef08822012-09-17 22:18:48 +00001321 SchedClassTables SchedTables;
Craig Topper29c55dcb2016-02-13 06:03:32 +00001322 for (const CodeGenProcModel &ProcModel : SchedModels.procModels()) {
1323 GenSchedClassTables(ProcModel, SchedTables);
Andrew Trick9ef08822012-09-17 22:18:48 +00001324 }
Andrew Tricka72fca62012-09-17 22:18:50 +00001325 EmitSchedClassTables(SchedTables, OS);
1326
1327 // Emit the processor machine model
1328 EmitProcessorModels(OS);
1329 // Emit the processor lookup data
1330 EmitProcessorLookup(OS);
Andrew Trick9ef08822012-09-17 22:18:48 +00001331
Craig Topper194cb742017-10-24 15:50:55 +00001332 OS << "\n#undef DBGFIELD";
Jim Laskey86f002c2005-10-27 19:47:21 +00001333}
1334
Benjamin Kramerc321e532016-06-08 19:09:22 +00001335void SubtargetEmitter::EmitSchedModelHelpers(const std::string &ClassName,
Andrew Trickc6c88152012-09-18 03:41:43 +00001336 raw_ostream &OS) {
1337 OS << "unsigned " << ClassName
1338 << "\n::resolveSchedClass(unsigned SchedClass, const MachineInstr *MI,"
1339 << " const TargetSchedModel *SchedModel) const {\n";
1340
1341 std::vector<Record*> Prologs = Records.getAllDerivedDefinitions("PredicateProlog");
1342 std::sort(Prologs.begin(), Prologs.end(), LessRecord());
Craig Topper29c55dcb2016-02-13 06:03:32 +00001343 for (Record *P : Prologs) {
1344 OS << P->getValueAsString("Code") << '\n';
Andrew Trickc6c88152012-09-18 03:41:43 +00001345 }
1346 IdxVec VariantClasses;
Craig Topper29c55dcb2016-02-13 06:03:32 +00001347 for (const CodeGenSchedClass &SC : SchedModels.schedClasses()) {
1348 if (SC.Transitions.empty())
Andrew Trickc6c88152012-09-18 03:41:43 +00001349 continue;
Craig Topper29c55dcb2016-02-13 06:03:32 +00001350 VariantClasses.push_back(SC.Index);
Andrew Trickc6c88152012-09-18 03:41:43 +00001351 }
1352 if (!VariantClasses.empty()) {
1353 OS << " switch (SchedClass) {\n";
Craig Topper29c55dcb2016-02-13 06:03:32 +00001354 for (unsigned VC : VariantClasses) {
1355 const CodeGenSchedClass &SC = SchedModels.getSchedClass(VC);
1356 OS << " case " << VC << ": // " << SC.Name << '\n';
Andrew Trickc6c88152012-09-18 03:41:43 +00001357 IdxVec ProcIndices;
Craig Topper29c55dcb2016-02-13 06:03:32 +00001358 for (const CodeGenSchedTransition &T : SC.Transitions) {
Andrew Trickc6c88152012-09-18 03:41:43 +00001359 IdxVec PI;
Craig Topper29c55dcb2016-02-13 06:03:32 +00001360 std::set_union(T.ProcIndices.begin(), T.ProcIndices.end(),
Andrew Trickc6c88152012-09-18 03:41:43 +00001361 ProcIndices.begin(), ProcIndices.end(),
1362 std::back_inserter(PI));
1363 ProcIndices.swap(PI);
1364 }
Craig Topper29c55dcb2016-02-13 06:03:32 +00001365 for (unsigned PI : ProcIndices) {
Andrew Trickc6c88152012-09-18 03:41:43 +00001366 OS << " ";
Craig Topper29c55dcb2016-02-13 06:03:32 +00001367 if (PI != 0)
1368 OS << "if (SchedModel->getProcessorID() == " << PI << ") ";
1369 OS << "{ // " << (SchedModels.procModelBegin() + PI)->ModelName
Andrew Trickc6c88152012-09-18 03:41:43 +00001370 << '\n';
Craig Topper29c55dcb2016-02-13 06:03:32 +00001371 for (const CodeGenSchedTransition &T : SC.Transitions) {
1372 if (PI != 0 && !std::count(T.ProcIndices.begin(),
1373 T.ProcIndices.end(), PI)) {
Andrew Trickc6c88152012-09-18 03:41:43 +00001374 continue;
1375 }
Arnold Schwaighofer218f6d82013-06-05 14:06:50 +00001376 OS << " if (";
Craig Topper29c55dcb2016-02-13 06:03:32 +00001377 for (RecIter RI = T.PredTerm.begin(), RE = T.PredTerm.end();
Andrew Trickc6c88152012-09-18 03:41:43 +00001378 RI != RE; ++RI) {
Craig Topper29c55dcb2016-02-13 06:03:32 +00001379 if (RI != T.PredTerm.begin())
Andrew Trickc6c88152012-09-18 03:41:43 +00001380 OS << "\n && ";
1381 OS << "(" << (*RI)->getValueAsString("Predicate") << ")";
1382 }
1383 OS << ")\n"
Craig Topper29c55dcb2016-02-13 06:03:32 +00001384 << " return " << T.ToClassIdx << "; // "
1385 << SchedModels.getSchedClass(T.ToClassIdx).Name << '\n';
Andrew Trickc6c88152012-09-18 03:41:43 +00001386 }
1387 OS << " }\n";
Craig Topper29c55dcb2016-02-13 06:03:32 +00001388 if (PI == 0)
Andrew Trickc6c88152012-09-18 03:41:43 +00001389 break;
1390 }
Andrew Trickbf8a28d2013-03-16 18:58:55 +00001391 if (SC.isInferred())
1392 OS << " return " << SC.Index << ";\n";
Andrew Trickc6c88152012-09-18 03:41:43 +00001393 OS << " break;\n";
1394 }
1395 OS << " };\n";
1396 }
1397 OS << " report_fatal_error(\"Expected a variant SchedClass\");\n"
1398 << "} // " << ClassName << "::resolveSchedClass\n";
1399}
1400
Krzysztof Parzyszek788e7682017-09-14 20:44:20 +00001401void SubtargetEmitter::EmitHwModeCheck(const std::string &ClassName,
1402 raw_ostream &OS) {
1403 const CodeGenHwModes &CGH = TGT.getHwModes();
1404 assert(CGH.getNumModeIds() > 0);
1405 if (CGH.getNumModeIds() == 1)
1406 return;
1407
1408 OS << "unsigned " << ClassName << "::getHwMode() const {\n";
1409 for (unsigned M = 1, NumModes = CGH.getNumModeIds(); M != NumModes; ++M) {
1410 const HwMode &HM = CGH.getMode(M);
1411 OS << " if (checkFeatures(\"" << HM.Features
1412 << "\")) return " << M << ";\n";
1413 }
1414 OS << " return 0;\n}\n";
1415}
1416
Jim Laskey86f002c2005-10-27 19:47:21 +00001417//
Jim Laskeya2b52352005-10-26 17:30:34 +00001418// ParseFeaturesFunction - Produces a subtarget specific function for parsing
1419// the subtarget features string.
1420//
Evan Cheng54b68e32011-07-01 20:45:01 +00001421void SubtargetEmitter::ParseFeaturesFunction(raw_ostream &OS,
1422 unsigned NumFeatures,
1423 unsigned NumProcs) {
Jim Laskeydffe5972005-10-28 21:47:29 +00001424 std::vector<Record*> Features =
1425 Records.getAllDerivedDefinitions("SubtargetFeature");
Duraid Madina018da4f2005-12-30 14:56:37 +00001426 std::sort(Features.begin(), Features.end(), LessRecord());
Jim Laskeya2b52352005-10-26 17:30:34 +00001427
Andrew Trickdb6ed642011-04-01 01:56:55 +00001428 OS << "// ParseSubtargetFeatures - Parses features string setting specified\n"
1429 << "// subtarget options.\n"
Evan Chengfe6e4052011-06-30 01:53:36 +00001430 << "void llvm::";
Jim Laskeya2b52352005-10-26 17:30:34 +00001431 OS << Target;
Evan Cheng1a72add62011-07-07 07:07:08 +00001432 OS << "Subtarget::ParseSubtargetFeatures(StringRef CPU, StringRef FS) {\n"
David Greenefb652a72010-01-05 17:47:41 +00001433 << " DEBUG(dbgs() << \"\\nFeatures:\" << FS);\n"
Hal Finkel060f5d22012-06-12 04:21:36 +00001434 << " DEBUG(dbgs() << \"\\nCPU:\" << CPU << \"\\n\\n\");\n";
Evan Cheng54b68e32011-07-01 20:45:01 +00001435
1436 if (Features.empty()) {
1437 OS << "}\n";
1438 return;
1439 }
1440
Andrew Trickba7b9212012-09-18 05:33:15 +00001441 OS << " InitMCProcessorInfo(CPU, FS);\n"
Michael Kupersteindb0712f2015-05-26 10:47:10 +00001442 << " const FeatureBitset& Bits = getFeatureBits();\n";
Bill Wendlinge6182262007-05-04 20:38:40 +00001443
Craig Topper29c55dcb2016-02-13 06:03:32 +00001444 for (Record *R : Features) {
Jim Laskeydffe5972005-10-28 21:47:29 +00001445 // Next record
Craig Topperbcd3c372017-05-31 21:12:46 +00001446 StringRef Instance = R->getName();
1447 StringRef Value = R->getValueAsString("Value");
1448 StringRef Attribute = R->getValueAsString("Attribute");
Evan Chengd98701c2006-01-27 08:09:42 +00001449
Dale Johannesen6ca3ccf2008-02-14 23:35:16 +00001450 if (Value=="true" || Value=="false")
Michael Kupersteindb0712f2015-05-26 10:47:10 +00001451 OS << " if (Bits[" << Target << "::"
1452 << Instance << "]) "
Dale Johannesen6ca3ccf2008-02-14 23:35:16 +00001453 << Attribute << " = " << Value << ";\n";
1454 else
Michael Kupersteindb0712f2015-05-26 10:47:10 +00001455 OS << " if (Bits[" << Target << "::"
1456 << Instance << "] && "
Evan Cheng54b68e32011-07-01 20:45:01 +00001457 << Attribute << " < " << Value << ") "
1458 << Attribute << " = " << Value << ";\n";
Jim Laskey802748c2005-11-01 20:06:59 +00001459 }
Anton Korobeynikov08bf4c02009-05-23 19:50:50 +00001460
Evan Chengfe6e4052011-06-30 01:53:36 +00001461 OS << "}\n";
Jim Laskeya2b52352005-10-26 17:30:34 +00001462}
1463
Anton Korobeynikov08bf4c02009-05-23 19:50:50 +00001464//
Jim Laskeycfda85a2005-10-21 19:00:04 +00001465// SubtargetEmitter::run - Main subtarget enumeration emitter.
1466//
Daniel Dunbar38a22bf2009-07-03 00:10:29 +00001467void SubtargetEmitter::run(raw_ostream &OS) {
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +00001468 emitSourceFileHeader("Subtarget Enumeration Source Fragment", OS);
Jim Laskeycfda85a2005-10-21 19:00:04 +00001469
Evan Cheng4d1ca962011-07-08 01:53:10 +00001470 OS << "\n#ifdef GET_SUBTARGETINFO_ENUM\n";
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001471 OS << "#undef GET_SUBTARGETINFO_ENUM\n\n";
Evan Cheng4d1ca962011-07-08 01:53:10 +00001472
1473 OS << "namespace llvm {\n";
Craig Topper094bbca2016-02-14 05:22:01 +00001474 Enumeration(OS);
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001475 OS << "} // end namespace llvm\n\n";
Evan Cheng4d1ca962011-07-08 01:53:10 +00001476 OS << "#endif // GET_SUBTARGETINFO_ENUM\n\n";
1477
Evan Cheng54b68e32011-07-01 20:45:01 +00001478 OS << "\n#ifdef GET_SUBTARGETINFO_MC_DESC\n";
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001479 OS << "#undef GET_SUBTARGETINFO_MC_DESC\n\n";
Anton Korobeynikov7d62e332010-04-18 20:31:01 +00001480
Evan Cheng54b68e32011-07-01 20:45:01 +00001481 OS << "namespace llvm {\n";
Evan Chengbc153d42011-07-14 20:59:42 +00001482#if 0
1483 OS << "namespace {\n";
1484#endif
Evan Cheng54b68e32011-07-01 20:45:01 +00001485 unsigned NumFeatures = FeatureKeyValues(OS);
Evan Chengbc153d42011-07-14 20:59:42 +00001486 OS << "\n";
Evan Cheng54b68e32011-07-01 20:45:01 +00001487 unsigned NumProcs = CPUKeyValues(OS);
Evan Chengbc153d42011-07-14 20:59:42 +00001488 OS << "\n";
Andrew Trick87255e32012-07-07 04:00:00 +00001489 EmitSchedModel(OS);
Evan Chengbc153d42011-07-14 20:59:42 +00001490 OS << "\n";
1491#if 0
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001492 OS << "} // end anonymous namespace\n\n";
Evan Chengbc153d42011-07-14 20:59:42 +00001493#endif
Evan Cheng54b68e32011-07-01 20:45:01 +00001494
1495 // MCInstrInfo initialization routine.
Craig Topper194cb742017-10-24 15:50:55 +00001496 OS << "\nstatic inline MCSubtargetInfo *create" << Target
Duncan P. N. Exon Smith754e21f2015-07-10 22:43:42 +00001497 << "MCSubtargetInfoImpl("
Daniel Sanders50f17232015-09-15 16:17:27 +00001498 << "const Triple &TT, StringRef CPU, StringRef FS) {\n";
Duncan P. N. Exon Smith754e21f2015-07-10 22:43:42 +00001499 OS << " return new MCSubtargetInfo(TT, CPU, FS, ";
Evan Cheng54b68e32011-07-01 20:45:01 +00001500 if (NumFeatures)
1501 OS << Target << "FeatureKV, ";
1502 else
Eric Christopherdc5072d2014-05-06 20:23:04 +00001503 OS << "None, ";
Evan Cheng54b68e32011-07-01 20:45:01 +00001504 if (NumProcs)
1505 OS << Target << "SubTypeKV, ";
1506 else
Eric Christopherdc5072d2014-05-06 20:23:04 +00001507 OS << "None, ";
Andrew Tricka72fca62012-09-17 22:18:50 +00001508 OS << '\n'; OS.indent(22);
Andrew Trickab722bd2012-09-18 03:18:56 +00001509 OS << Target << "ProcSchedKV, "
1510 << Target << "WriteProcResTable, "
1511 << Target << "WriteLatencyTable, "
1512 << Target << "ReadAdvanceTable, ";
Eugene Zelenko2bc2f332016-12-09 22:06:55 +00001513 OS << '\n'; OS.indent(22);
Andrew Trickbf8a28d2013-03-16 18:58:55 +00001514 if (SchedModels.hasItineraries()) {
Andrew Trickab722bd2012-09-18 03:18:56 +00001515 OS << Target << "Stages, "
Evan Cheng54b68e32011-07-01 20:45:01 +00001516 << Target << "OperandCycles, "
Eric Christopherdc5072d2014-05-06 20:23:04 +00001517 << Target << "ForwardingPaths";
Evan Cheng54b68e32011-07-01 20:45:01 +00001518 } else
Eugene Zelenko2bc2f332016-12-09 22:06:55 +00001519 OS << "nullptr, nullptr, nullptr";
Eric Christopherdc5072d2014-05-06 20:23:04 +00001520 OS << ");\n}\n\n";
Evan Cheng54b68e32011-07-01 20:45:01 +00001521
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001522 OS << "} // end namespace llvm\n\n";
Evan Cheng54b68e32011-07-01 20:45:01 +00001523
1524 OS << "#endif // GET_SUBTARGETINFO_MC_DESC\n\n";
1525
1526 OS << "\n#ifdef GET_SUBTARGETINFO_TARGET_DESC\n";
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001527 OS << "#undef GET_SUBTARGETINFO_TARGET_DESC\n\n";
Evan Cheng54b68e32011-07-01 20:45:01 +00001528
1529 OS << "#include \"llvm/Support/Debug.h\"\n";
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001530 OS << "#include \"llvm/Support/raw_ostream.h\"\n\n";
Evan Cheng54b68e32011-07-01 20:45:01 +00001531 ParseFeaturesFunction(OS, NumFeatures, NumProcs);
1532
1533 OS << "#endif // GET_SUBTARGETINFO_TARGET_DESC\n\n";
1534
Evan Cheng0d639a22011-07-01 21:01:15 +00001535 // Create a TargetSubtargetInfo subclass to hide the MC layer initialization.
Evan Cheng54b68e32011-07-01 20:45:01 +00001536 OS << "\n#ifdef GET_SUBTARGETINFO_HEADER\n";
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001537 OS << "#undef GET_SUBTARGETINFO_HEADER\n\n";
Evan Cheng54b68e32011-07-01 20:45:01 +00001538
1539 std::string ClassName = Target + "GenSubtargetInfo";
1540 OS << "namespace llvm {\n";
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +00001541 OS << "class DFAPacketizer;\n";
Evan Cheng0d639a22011-07-01 21:01:15 +00001542 OS << "struct " << ClassName << " : public TargetSubtargetInfo {\n"
Daniel Sanders50f17232015-09-15 16:17:27 +00001543 << " explicit " << ClassName << "(const Triple &TT, StringRef CPU, "
Evan Cheng1a72add62011-07-07 07:07:08 +00001544 << "StringRef FS);\n"
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +00001545 << "public:\n"
Daniel Sandersa73f1fd2015-06-10 12:11:26 +00001546 << " unsigned resolveSchedClass(unsigned SchedClass, "
1547 << " const MachineInstr *DefMI,"
Craig Topper2d9361e2014-03-09 07:44:38 +00001548 << " const TargetSchedModel *SchedModel) const override;\n"
Sebastian Popac35a4d2011-12-06 17:34:16 +00001549 << " DFAPacketizer *createDFAPacketizer(const InstrItineraryData *IID)"
Krzysztof Parzyszek788e7682017-09-14 20:44:20 +00001550 << " const;\n";
1551 if (TGT.getHwModes().getNumModeIds() > 1)
1552 OS << " unsigned getHwMode() const override;\n";
1553 OS << "};\n"
1554 << "} // end namespace llvm\n\n";
Evan Cheng54b68e32011-07-01 20:45:01 +00001555
1556 OS << "#endif // GET_SUBTARGETINFO_HEADER\n\n";
1557
1558 OS << "\n#ifdef GET_SUBTARGETINFO_CTOR\n";
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001559 OS << "#undef GET_SUBTARGETINFO_CTOR\n\n";
Evan Cheng54b68e32011-07-01 20:45:01 +00001560
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001561 OS << "#include \"llvm/CodeGen/TargetSchedule.h\"\n\n";
Evan Cheng54b68e32011-07-01 20:45:01 +00001562 OS << "namespace llvm {\n";
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00001563 OS << "extern const llvm::SubtargetFeatureKV " << Target << "FeatureKV[];\n";
1564 OS << "extern const llvm::SubtargetFeatureKV " << Target << "SubTypeKV[];\n";
Andrew Tricka72fca62012-09-17 22:18:50 +00001565 OS << "extern const llvm::SubtargetInfoKV " << Target << "ProcSchedKV[];\n";
1566 OS << "extern const llvm::MCWriteProcResEntry "
1567 << Target << "WriteProcResTable[];\n";
1568 OS << "extern const llvm::MCWriteLatencyEntry "
1569 << Target << "WriteLatencyTable[];\n";
1570 OS << "extern const llvm::MCReadAdvanceEntry "
1571 << Target << "ReadAdvanceTable[];\n";
1572
Andrew Trickbf8a28d2013-03-16 18:58:55 +00001573 if (SchedModels.hasItineraries()) {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00001574 OS << "extern const llvm::InstrStage " << Target << "Stages[];\n";
1575 OS << "extern const unsigned " << Target << "OperandCycles[];\n";
Andrew Trick030e2f82012-07-07 03:59:48 +00001576 OS << "extern const unsigned " << Target << "ForwardingPaths[];\n";
Evan Chengbc153d42011-07-14 20:59:42 +00001577 }
1578
Daniel Sanders50f17232015-09-15 16:17:27 +00001579 OS << ClassName << "::" << ClassName << "(const Triple &TT, StringRef CPU, "
1580 << "StringRef FS)\n"
Duncan P. N. Exon Smith754e21f2015-07-10 22:43:42 +00001581 << " : TargetSubtargetInfo(TT, CPU, FS, ";
Evan Cheng54b68e32011-07-01 20:45:01 +00001582 if (NumFeatures)
Eric Christopherdc5072d2014-05-06 20:23:04 +00001583 OS << "makeArrayRef(" << Target << "FeatureKV, " << NumFeatures << "), ";
Evan Cheng54b68e32011-07-01 20:45:01 +00001584 else
Eric Christopherdc5072d2014-05-06 20:23:04 +00001585 OS << "None, ";
Evan Cheng54b68e32011-07-01 20:45:01 +00001586 if (NumProcs)
Eric Christopherdc5072d2014-05-06 20:23:04 +00001587 OS << "makeArrayRef(" << Target << "SubTypeKV, " << NumProcs << "), ";
Evan Cheng54b68e32011-07-01 20:45:01 +00001588 else
Eric Christopherdc5072d2014-05-06 20:23:04 +00001589 OS << "None, ";
Duncan P. N. Exon Smith754e21f2015-07-10 22:43:42 +00001590 OS << '\n'; OS.indent(24);
Andrew Trickab722bd2012-09-18 03:18:56 +00001591 OS << Target << "ProcSchedKV, "
1592 << Target << "WriteProcResTable, "
1593 << Target << "WriteLatencyTable, "
1594 << Target << "ReadAdvanceTable, ";
Duncan P. N. Exon Smith754e21f2015-07-10 22:43:42 +00001595 OS << '\n'; OS.indent(24);
Andrew Trickbf8a28d2013-03-16 18:58:55 +00001596 if (SchedModels.hasItineraries()) {
Andrew Trickab722bd2012-09-18 03:18:56 +00001597 OS << Target << "Stages, "
Evan Cheng54b68e32011-07-01 20:45:01 +00001598 << Target << "OperandCycles, "
Eric Christopherdc5072d2014-05-06 20:23:04 +00001599 << Target << "ForwardingPaths";
Evan Cheng54b68e32011-07-01 20:45:01 +00001600 } else
Eugene Zelenko2bc2f332016-12-09 22:06:55 +00001601 OS << "nullptr, nullptr, nullptr";
Duncan P. N. Exon Smith754e21f2015-07-10 22:43:42 +00001602 OS << ") {}\n\n";
Andrew Tricka72fca62012-09-17 22:18:50 +00001603
Andrew Trickc6c88152012-09-18 03:41:43 +00001604 EmitSchedModelHelpers(ClassName, OS);
Krzysztof Parzyszek788e7682017-09-14 20:44:20 +00001605 EmitHwModeCheck(ClassName, OS);
Andrew Trickc6c88152012-09-18 03:41:43 +00001606
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001607 OS << "} // end namespace llvm\n\n";
Evan Cheng54b68e32011-07-01 20:45:01 +00001608
1609 OS << "#endif // GET_SUBTARGETINFO_CTOR\n\n";
Jim Laskeycfda85a2005-10-21 19:00:04 +00001610}
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +00001611
1612namespace llvm {
1613
1614void EmitSubtarget(RecordKeeper &RK, raw_ostream &OS) {
Andrew Trick87255e32012-07-07 04:00:00 +00001615 CodeGenTarget CGTarget(RK);
1616 SubtargetEmitter(RK, CGTarget).run(OS);
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +00001617}
1618
Eugene Zelenko75259bb2016-05-17 17:04:23 +00001619} // end namespace llvm