Jim Laskey | cfda85a | 2005-10-21 19:00:04 +0000 | [diff] [blame] | 1 | //===- SubtargetEmitter.cpp - Generate subtarget enumerations -------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 8adcd9f | 2007-12-29 20:37:13 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Jim Laskey | cfda85a | 2005-10-21 19:00:04 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Chris Lattner | 73fbe14 | 2006-03-03 02:04:07 +0000 | [diff] [blame] | 10 | // This tablegen backend emits subtarget enumerations. |
Jim Laskey | cfda85a | 2005-10-21 19:00:04 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Jim Laskey | cfda85a | 2005-10-21 19:00:04 +0000 | [diff] [blame] | 14 | #include "CodeGenTarget.h" |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 15 | #include "CodeGenSchedule.h" |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/STLExtras.h" |
Chandler Carruth | 91d19d8 | 2012-12-04 10:37:14 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/StringExtras.h" |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCInstrItineraries.h" |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 19 | #include "llvm/MC/SubtargetFeature.h" |
Chandler Carruth | 91d19d8 | 2012-12-04 10:37:14 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Debug.h" |
| 21 | #include "llvm/Support/Format.h" |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 22 | #include "llvm/TableGen/Error.h" |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 23 | #include "llvm/TableGen/Record.h" |
| 24 | #include "llvm/TableGen/TableGenBackend.h" |
Jeff Cohen | b0aa47b | 2005-10-28 01:43:09 +0000 | [diff] [blame] | 25 | #include <algorithm> |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 26 | #include <map> |
| 27 | #include <string> |
| 28 | #include <vector> |
Hans Wennborg | 083ca9b | 2015-10-06 23:24:35 +0000 | [diff] [blame] | 29 | |
Jim Laskey | cfda85a | 2005-10-21 19:00:04 +0000 | [diff] [blame] | 30 | using namespace llvm; |
| 31 | |
Chandler Carruth | 97acce2 | 2014-04-22 03:06:00 +0000 | [diff] [blame] | 32 | #define DEBUG_TYPE "subtarget-emitter" |
| 33 | |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 34 | namespace { |
| 35 | class SubtargetEmitter { |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 36 | // Each processor has a SchedClassDesc table with an entry for each SchedClass. |
| 37 | // The SchedClassDesc table indexes into a global write resource table, write |
| 38 | // latency table, and read advance table. |
| 39 | struct SchedClassTables { |
| 40 | std::vector<std::vector<MCSchedClassDesc> > ProcSchedClasses; |
| 41 | std::vector<MCWriteProcResEntry> WriteProcResources; |
| 42 | std::vector<MCWriteLatencyEntry> WriteLatencies; |
Andrew Trick | cfe222c | 2012-09-19 04:43:19 +0000 | [diff] [blame] | 43 | std::vector<std::string> WriterNames; |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 44 | std::vector<MCReadAdvanceEntry> ReadAdvanceEntries; |
| 45 | |
| 46 | // Reserve an invalid entry at index 0 |
| 47 | SchedClassTables() { |
| 48 | ProcSchedClasses.resize(1); |
| 49 | WriteProcResources.resize(1); |
| 50 | WriteLatencies.resize(1); |
Andrew Trick | cfe222c | 2012-09-19 04:43:19 +0000 | [diff] [blame] | 51 | WriterNames.push_back("InvalidWrite"); |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 52 | ReadAdvanceEntries.resize(1); |
| 53 | } |
| 54 | }; |
| 55 | |
| 56 | struct LessWriteProcResources { |
| 57 | bool operator()(const MCWriteProcResEntry &LHS, |
| 58 | const MCWriteProcResEntry &RHS) { |
| 59 | return LHS.ProcResourceIdx < RHS.ProcResourceIdx; |
| 60 | } |
| 61 | }; |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 62 | |
| 63 | RecordKeeper &Records; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 64 | CodeGenSchedModels &SchedModels; |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 65 | std::string Target; |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 66 | |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 67 | void Enumeration(raw_ostream &OS, const char *ClassName); |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 68 | unsigned FeatureKeyValues(raw_ostream &OS); |
| 69 | unsigned CPUKeyValues(raw_ostream &OS); |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 70 | void FormItineraryStageString(const std::string &Names, |
| 71 | Record *ItinData, std::string &ItinString, |
| 72 | unsigned &NStages); |
| 73 | void FormItineraryOperandCycleString(Record *ItinData, std::string &ItinString, |
| 74 | unsigned &NOperandCycles); |
| 75 | void FormItineraryBypassString(const std::string &Names, |
| 76 | Record *ItinData, |
| 77 | std::string &ItinString, unsigned NOperandCycles); |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 78 | void EmitStageAndOperandCycleData(raw_ostream &OS, |
| 79 | std::vector<std::vector<InstrItinerary> > |
| 80 | &ProcItinLists); |
| 81 | void EmitItineraries(raw_ostream &OS, |
| 82 | std::vector<std::vector<InstrItinerary> > |
| 83 | &ProcItinLists); |
| 84 | void EmitProcessorProp(raw_ostream &OS, const Record *R, const char *Name, |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 85 | char Separator); |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 86 | void EmitProcessorResources(const CodeGenProcModel &ProcModel, |
| 87 | raw_ostream &OS); |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 88 | Record *FindWriteResources(const CodeGenSchedRW &SchedWrite, |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 89 | const CodeGenProcModel &ProcModel); |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 90 | Record *FindReadAdvance(const CodeGenSchedRW &SchedRead, |
| 91 | const CodeGenProcModel &ProcModel); |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 92 | void ExpandProcResources(RecVec &PRVec, std::vector<int64_t> &Cycles, |
| 93 | const CodeGenProcModel &ProcModel); |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 94 | void GenSchedClassTables(const CodeGenProcModel &ProcModel, |
| 95 | SchedClassTables &SchedTables); |
Andrew Trick | a72fca6 | 2012-09-17 22:18:50 +0000 | [diff] [blame] | 96 | void EmitSchedClassTables(SchedClassTables &SchedTables, raw_ostream &OS); |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 97 | void EmitProcessorModels(raw_ostream &OS); |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 98 | void EmitProcessorLookup(raw_ostream &OS); |
Andrew Trick | c6c8815 | 2012-09-18 03:41:43 +0000 | [diff] [blame] | 99 | void EmitSchedModelHelpers(std::string ClassName, raw_ostream &OS); |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 100 | void EmitSchedModel(raw_ostream &OS); |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 101 | void ParseFeaturesFunction(raw_ostream &OS, unsigned NumFeatures, |
| 102 | unsigned NumProcs); |
| 103 | |
| 104 | public: |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 105 | SubtargetEmitter(RecordKeeper &R, CodeGenTarget &TGT): |
| 106 | Records(R), SchedModels(TGT.getSchedModels()), Target(TGT.getName()) {} |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 107 | |
| 108 | void run(raw_ostream &o); |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 109 | }; |
Hans Wennborg | 083ca9b | 2015-10-06 23:24:35 +0000 | [diff] [blame] | 110 | } // end anonymous namespace |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 111 | |
Jim Laskey | a1beea6 | 2005-10-22 07:59:56 +0000 | [diff] [blame] | 112 | // |
Jim Laskey | a2b5235 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 113 | // Enumeration - Emit the specified class as an enumeration. |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 114 | // |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 115 | void SubtargetEmitter::Enumeration(raw_ostream &OS, |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 116 | const char *ClassName) { |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 117 | // Get all records of class and sort |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 118 | std::vector<Record*> DefList = Records.getAllDerivedDefinitions(ClassName); |
Duraid Madina | 018da4f | 2005-12-30 14:56:37 +0000 | [diff] [blame] | 119 | std::sort(DefList.begin(), DefList.end(), LessRecord()); |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 120 | |
Evan Cheng | a2e6129 | 2011-04-15 19:35:46 +0000 | [diff] [blame] | 121 | unsigned N = DefList.size(); |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 122 | if (N == 0) |
| 123 | return; |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 124 | if (N > MAX_SUBTARGET_FEATURES) |
| 125 | PrintFatalError("Too many subtarget features! Bump MAX_SUBTARGET_FEATURES."); |
Evan Cheng | a2e6129 | 2011-04-15 19:35:46 +0000 | [diff] [blame] | 126 | |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 127 | OS << "namespace " << Target << " {\n"; |
| 128 | |
Reid Kleckner | 294fa7a | 2015-03-09 20:23:14 +0000 | [diff] [blame] | 129 | // Open enumeration. Use a 64-bit underlying type. |
| 130 | OS << "enum : uint64_t {\n"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 131 | |
Reid Kleckner | 294fa7a | 2015-03-09 20:23:14 +0000 | [diff] [blame] | 132 | // For each record |
| 133 | for (unsigned i = 0; i < N;) { |
| 134 | // Next record |
| 135 | Record *Def = DefList[i]; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 136 | |
Reid Kleckner | 294fa7a | 2015-03-09 20:23:14 +0000 | [diff] [blame] | 137 | // Get and emit name |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 138 | OS << " " << Def->getName() << " = " << i; |
Reid Kleckner | 294fa7a | 2015-03-09 20:23:14 +0000 | [diff] [blame] | 139 | if (++i < N) OS << ","; |
Michael Kuperstein | efd7a96 | 2015-02-19 11:38:11 +0000 | [diff] [blame] | 140 | |
Reid Kleckner | 294fa7a | 2015-03-09 20:23:14 +0000 | [diff] [blame] | 141 | OS << "\n"; |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 142 | } |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 143 | |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 144 | // Close enumeration and namespace |
| 145 | OS << "};\n}\n"; |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | // |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 149 | // FeatureKeyValues - Emit data of all the subtarget features. Used by the |
| 150 | // command line. |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 151 | // |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 152 | unsigned SubtargetEmitter::FeatureKeyValues(raw_ostream &OS) { |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 153 | // Gather and sort all the features |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 154 | std::vector<Record*> FeatureList = |
| 155 | Records.getAllDerivedDefinitions("SubtargetFeature"); |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 156 | |
| 157 | if (FeatureList.empty()) |
| 158 | return 0; |
| 159 | |
Jim Grosbach | 56938af | 2008-09-11 17:05:32 +0000 | [diff] [blame] | 160 | std::sort(FeatureList.begin(), FeatureList.end(), LessRecordFieldName()); |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 161 | |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 162 | // Begin feature table |
Jim Laskey | a2b5235 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 163 | OS << "// Sorted (by key) array of values for CPU features.\n" |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 164 | << "extern const llvm::SubtargetFeatureKV " << Target |
| 165 | << "FeatureKV[] = {\n"; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 166 | |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 167 | // For each feature |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 168 | unsigned NumFeatures = 0; |
Jim Laskey | 3f7d047 | 2006-12-12 20:55:58 +0000 | [diff] [blame] | 169 | for (unsigned i = 0, N = FeatureList.size(); i < N; ++i) { |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 170 | // Next feature |
| 171 | Record *Feature = FeatureList[i]; |
| 172 | |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 173 | const std::string &Name = Feature->getName(); |
| 174 | const std::string &CommandLineName = Feature->getValueAsString("Name"); |
| 175 | const std::string &Desc = Feature->getValueAsString("Desc"); |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 176 | |
Jim Laskey | 3f7d047 | 2006-12-12 20:55:58 +0000 | [diff] [blame] | 177 | if (CommandLineName.empty()) continue; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 178 | |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 179 | // Emit as { "feature", "description", { featureEnum }, { i1 , i2 , ... , in } } |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 180 | OS << " { " |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 181 | << "\"" << CommandLineName << "\", " |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 182 | << "\"" << Desc << "\", " |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 183 | << "{ " << Target << "::" << Name << " }, "; |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 184 | |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 185 | const std::vector<Record*> &ImpliesList = |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 186 | Feature->getValueAsListOfDefs("Implies"); |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 187 | |
Craig Topper | 4ceea0a | 2016-01-03 08:57:41 +0000 | [diff] [blame^] | 188 | OS << "{"; |
| 189 | for (unsigned j = 0, M = ImpliesList.size(); j < M;) { |
| 190 | OS << " " << Target << "::" << ImpliesList[j]->getName(); |
| 191 | if (++j < M) OS << ","; |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 192 | } |
Craig Topper | 4ceea0a | 2016-01-03 08:57:41 +0000 | [diff] [blame^] | 193 | OS << " }"; |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 194 | |
| 195 | OS << " }"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 196 | ++NumFeatures; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 197 | |
Jim Laskey | 3763a50 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 198 | // Depending on 'if more in the list' emit comma |
Jim Laskey | 3f7d047 | 2006-12-12 20:55:58 +0000 | [diff] [blame] | 199 | if ((i + 1) < N) OS << ","; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 200 | |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 201 | OS << "\n"; |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 202 | } |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 203 | |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 204 | // End feature table |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 205 | OS << "};\n"; |
| 206 | |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 207 | return NumFeatures; |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | // |
| 211 | // CPUKeyValues - Emit data of all the subtarget processors. Used by command |
| 212 | // line. |
| 213 | // |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 214 | unsigned SubtargetEmitter::CPUKeyValues(raw_ostream &OS) { |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 215 | // Gather and sort processor information |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 216 | std::vector<Record*> ProcessorList = |
| 217 | Records.getAllDerivedDefinitions("Processor"); |
Duraid Madina | 018da4f | 2005-12-30 14:56:37 +0000 | [diff] [blame] | 218 | std::sort(ProcessorList.begin(), ProcessorList.end(), LessRecordFieldName()); |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 219 | |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 220 | // Begin processor table |
Jim Laskey | a2b5235 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 221 | OS << "// Sorted (by key) array of values for CPU subtype.\n" |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 222 | << "extern const llvm::SubtargetFeatureKV " << Target |
| 223 | << "SubTypeKV[] = {\n"; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 224 | |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 225 | // For each processor |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 226 | for (unsigned i = 0, N = ProcessorList.size(); i < N;) { |
| 227 | // Next processor |
| 228 | Record *Processor = ProcessorList[i]; |
| 229 | |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 230 | const std::string &Name = Processor->getValueAsString("Name"); |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 231 | const std::vector<Record*> &FeatureList = |
Chris Lattner | 7ad0bed | 2005-10-28 22:49:02 +0000 | [diff] [blame] | 232 | Processor->getValueAsListOfDefs("Features"); |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 233 | |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 234 | // Emit as { "cpu", "description", { f1 , f2 , ... fn } }, |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 235 | OS << " { " |
| 236 | << "\"" << Name << "\", " |
| 237 | << "\"Select the " << Name << " processor\", "; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 238 | |
Craig Topper | 4ceea0a | 2016-01-03 08:57:41 +0000 | [diff] [blame^] | 239 | OS << "{"; |
| 240 | for (unsigned j = 0, M = FeatureList.size(); j < M;) { |
| 241 | OS << " " << Target << "::" << FeatureList[j]->getName(); |
| 242 | if (++j < M) OS << ","; |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 243 | } |
Craig Topper | 4ceea0a | 2016-01-03 08:57:41 +0000 | [diff] [blame^] | 244 | OS << " }"; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 245 | |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 246 | // The { } is for the "implies" section of this data structure. |
| 247 | OS << ", { } }"; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 248 | |
Jim Laskey | 3763a50 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 249 | // Depending on 'if more in the list' emit comma |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 250 | if (++i < N) OS << ","; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 251 | |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 252 | OS << "\n"; |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 253 | } |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 254 | |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 255 | // End processor table |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 256 | OS << "};\n"; |
| 257 | |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 258 | return ProcessorList.size(); |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 259 | } |
Jim Laskey | a1beea6 | 2005-10-22 07:59:56 +0000 | [diff] [blame] | 260 | |
Jim Laskey | a2b5235 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 261 | // |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 262 | // FormItineraryStageString - Compose a string containing the stage |
| 263 | // data initialization for the specified itinerary. N is the number |
| 264 | // of stages. |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 265 | // |
Anton Korobeynikov | 7d62e33 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 266 | void SubtargetEmitter::FormItineraryStageString(const std::string &Name, |
| 267 | Record *ItinData, |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 268 | std::string &ItinString, |
| 269 | unsigned &NStages) { |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 270 | // Get states list |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 271 | const std::vector<Record*> &StageList = |
| 272 | ItinData->getValueAsListOfDefs("Stages"); |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 273 | |
| 274 | // For each stage |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 275 | unsigned N = NStages = StageList.size(); |
Christopher Lamb | 8996dce | 2007-04-22 09:04:24 +0000 | [diff] [blame] | 276 | for (unsigned i = 0; i < N;) { |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 277 | // Next stage |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 278 | const Record *Stage = StageList[i]; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 279 | |
Anton Korobeynikov | 0bdc634 | 2010-04-07 18:19:32 +0000 | [diff] [blame] | 280 | // Form string as ,{ cycles, u1 | u2 | ... | un, timeinc, kind } |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 281 | int Cycles = Stage->getValueAsInt("Cycles"); |
Jim Laskey | d6d3afb | 2005-11-03 22:47:41 +0000 | [diff] [blame] | 282 | ItinString += " { " + itostr(Cycles) + ", "; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 283 | |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 284 | // Get unit list |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 285 | const std::vector<Record*> &UnitList = Stage->getValueAsListOfDefs("Units"); |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 286 | |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 287 | // For each unit |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 288 | for (unsigned j = 0, M = UnitList.size(); j < M;) { |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 289 | // Add name and bitwise or |
Anton Korobeynikov | 7d62e33 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 290 | ItinString += Name + "FU::" + UnitList[j]->getName(); |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 291 | if (++j < M) ItinString += " | "; |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 292 | } |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 293 | |
David Goodwin | b369ee4 | 2009-08-12 18:31:53 +0000 | [diff] [blame] | 294 | int TimeInc = Stage->getValueAsInt("TimeInc"); |
| 295 | ItinString += ", " + itostr(TimeInc); |
| 296 | |
Anton Korobeynikov | 0bdc634 | 2010-04-07 18:19:32 +0000 | [diff] [blame] | 297 | int Kind = Stage->getValueAsInt("Kind"); |
| 298 | ItinString += ", (llvm::InstrStage::ReservationKinds)" + itostr(Kind); |
| 299 | |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 300 | // Close off stage |
| 301 | ItinString += " }"; |
Christopher Lamb | 8996dce | 2007-04-22 09:04:24 +0000 | [diff] [blame] | 302 | if (++i < N) ItinString += ", "; |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 303 | } |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | // |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 307 | // FormItineraryOperandCycleString - Compose a string containing the |
| 308 | // operand cycle initialization for the specified itinerary. N is the |
| 309 | // number of operands that has cycles specified. |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 310 | // |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 311 | void SubtargetEmitter::FormItineraryOperandCycleString(Record *ItinData, |
| 312 | std::string &ItinString, unsigned &NOperandCycles) { |
| 313 | // Get operand cycle list |
| 314 | const std::vector<int64_t> &OperandCycleList = |
| 315 | ItinData->getValueAsListOfInts("OperandCycles"); |
| 316 | |
| 317 | // For each operand cycle |
| 318 | unsigned N = NOperandCycles = OperandCycleList.size(); |
| 319 | for (unsigned i = 0; i < N;) { |
| 320 | // Next operand cycle |
| 321 | const int OCycle = OperandCycleList[i]; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 322 | |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 323 | ItinString += " " + itostr(OCycle); |
| 324 | if (++i < N) ItinString += ", "; |
| 325 | } |
| 326 | } |
| 327 | |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 328 | void SubtargetEmitter::FormItineraryBypassString(const std::string &Name, |
| 329 | Record *ItinData, |
| 330 | std::string &ItinString, |
| 331 | unsigned NOperandCycles) { |
| 332 | const std::vector<Record*> &BypassList = |
| 333 | ItinData->getValueAsListOfDefs("Bypasses"); |
| 334 | unsigned N = BypassList.size(); |
Evan Cheng | 4a010fd | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 335 | unsigned i = 0; |
| 336 | for (; i < N;) { |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 337 | ItinString += Name + "Bypass::" + BypassList[i]->getName(); |
Evan Cheng | 4a010fd | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 338 | if (++i < NOperandCycles) ItinString += ", "; |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 339 | } |
Evan Cheng | 4a010fd | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 340 | for (; i < NOperandCycles;) { |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 341 | ItinString += " 0"; |
Evan Cheng | 4a010fd | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 342 | if (++i < NOperandCycles) ItinString += ", "; |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 346 | // |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 347 | // EmitStageAndOperandCycleData - Generate unique itinerary stages and operand |
| 348 | // cycle tables. Create a list of InstrItinerary objects (ProcItinLists) indexed |
| 349 | // by CodeGenSchedClass::Index. |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 350 | // |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 351 | void SubtargetEmitter:: |
| 352 | EmitStageAndOperandCycleData(raw_ostream &OS, |
| 353 | std::vector<std::vector<InstrItinerary> > |
| 354 | &ProcItinLists) { |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 355 | |
Andrew Trick | fb982dd | 2012-07-09 20:43:03 +0000 | [diff] [blame] | 356 | // Multiple processor models may share an itinerary record. Emit it once. |
| 357 | SmallPtrSet<Record*, 8> ItinsDefSet; |
| 358 | |
Anton Korobeynikov | 7d62e33 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 359 | // Emit functional units for all the itineraries. |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 360 | for (CodeGenSchedModels::ProcIter PI = SchedModels.procModelBegin(), |
| 361 | PE = SchedModels.procModelEnd(); PI != PE; ++PI) { |
Anton Korobeynikov | 7d62e33 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 362 | |
David Blaikie | 70573dc | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 363 | if (!ItinsDefSet.insert(PI->ItinsDef).second) |
Andrew Trick | fb982dd | 2012-07-09 20:43:03 +0000 | [diff] [blame] | 364 | continue; |
| 365 | |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 366 | std::vector<Record*> FUs = PI->ItinsDef->getValueAsListOfDefs("FU"); |
Anton Korobeynikov | 7d62e33 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 367 | if (FUs.empty()) |
| 368 | continue; |
| 369 | |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 370 | const std::string &Name = PI->ItinsDef->getName(); |
| 371 | OS << "\n// Functional units for \"" << Name << "\"\n" |
Anton Korobeynikov | 7d62e33 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 372 | << "namespace " << Name << "FU {\n"; |
| 373 | |
| 374 | for (unsigned j = 0, FUN = FUs.size(); j < FUN; ++j) |
Hal Finkel | 8db5547 | 2012-06-22 20:27:13 +0000 | [diff] [blame] | 375 | OS << " const unsigned " << FUs[j]->getName() |
| 376 | << " = 1 << " << j << ";\n"; |
Anton Korobeynikov | 7d62e33 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 377 | |
| 378 | OS << "}\n"; |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 379 | |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 380 | std::vector<Record*> BPs = PI->ItinsDef->getValueAsListOfDefs("BP"); |
Alexander Kornienko | 8c0809c | 2015-01-15 11:41:30 +0000 | [diff] [blame] | 381 | if (!BPs.empty()) { |
Evan Cheng | 4a010fd | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 382 | OS << "\n// Pipeline forwarding pathes for itineraries \"" << Name |
| 383 | << "\"\n" << "namespace " << Name << "Bypass {\n"; |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 384 | |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 385 | OS << " const unsigned NoBypass = 0;\n"; |
Evan Cheng | 4a010fd | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 386 | for (unsigned j = 0, BPN = BPs.size(); j < BPN; ++j) |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 387 | OS << " const unsigned " << BPs[j]->getName() |
Evan Cheng | 4a010fd | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 388 | << " = 1 << " << j << ";\n"; |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 389 | |
Evan Cheng | 4a010fd | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 390 | OS << "}\n"; |
| 391 | } |
Anton Korobeynikov | 7d62e33 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 392 | } |
| 393 | |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 394 | // Begin stages table |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 395 | std::string StageTable = "\nextern const llvm::InstrStage " + Target + |
| 396 | "Stages[] = {\n"; |
Anton Korobeynikov | 0bdc634 | 2010-04-07 18:19:32 +0000 | [diff] [blame] | 397 | StageTable += " { 0, 0, 0, llvm::InstrStage::Required }, // No itinerary\n"; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 398 | |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 399 | // Begin operand cycle table |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 400 | std::string OperandCycleTable = "extern const unsigned " + Target + |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 401 | "OperandCycles[] = {\n"; |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 402 | OperandCycleTable += " 0, // No itinerary\n"; |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 403 | |
| 404 | // Begin pipeline bypass table |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 405 | std::string BypassTable = "extern const unsigned " + Target + |
Andrew Trick | 030e2f8 | 2012-07-07 03:59:48 +0000 | [diff] [blame] | 406 | "ForwardingPaths[] = {\n"; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 407 | BypassTable += " 0, // No itinerary\n"; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 408 | |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 409 | // For each Itinerary across all processors, add a unique entry to the stages, |
| 410 | // operand cycles, and pipepine bypess tables. Then add the new Itinerary |
| 411 | // object with computed offsets to the ProcItinLists result. |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 412 | unsigned StageCount = 1, OperandCycleCount = 1; |
Evan Cheng | 4a010fd | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 413 | std::map<std::string, unsigned> ItinStageMap, ItinOperandMap; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 414 | for (CodeGenSchedModels::ProcIter PI = SchedModels.procModelBegin(), |
| 415 | PE = SchedModels.procModelEnd(); PI != PE; ++PI) { |
| 416 | const CodeGenProcModel &ProcModel = *PI; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 417 | |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 418 | // Add process itinerary to the list. |
| 419 | ProcItinLists.resize(ProcItinLists.size()+1); |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 420 | |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 421 | // If this processor defines no itineraries, then leave the itinerary list |
| 422 | // empty. |
| 423 | std::vector<InstrItinerary> &ItinList = ProcItinLists.back(); |
Andrew Trick | bf8a28d | 2013-03-16 18:58:55 +0000 | [diff] [blame] | 424 | if (!ProcModel.hasItineraries()) |
Andrew Trick | 9c30267 | 2012-06-22 03:58:51 +0000 | [diff] [blame] | 425 | continue; |
Andrew Trick | 9c30267 | 2012-06-22 03:58:51 +0000 | [diff] [blame] | 426 | |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 427 | const std::string &Name = ProcModel.ItinsDef->getName(); |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 428 | |
Andrew Trick | bf8a28d | 2013-03-16 18:58:55 +0000 | [diff] [blame] | 429 | ItinList.resize(SchedModels.numInstrSchedClasses()); |
| 430 | assert(ProcModel.ItinDefList.size() == ItinList.size() && "bad Itins"); |
| 431 | |
| 432 | for (unsigned SchedClassIdx = 0, SchedClassEnd = ItinList.size(); |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 433 | SchedClassIdx < SchedClassEnd; ++SchedClassIdx) { |
| 434 | |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 435 | // Next itinerary data |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 436 | Record *ItinData = ProcModel.ItinDefList[SchedClassIdx]; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 437 | |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 438 | // Get string and stage count |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 439 | std::string ItinStageString; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 440 | unsigned NStages = 0; |
| 441 | if (ItinData) |
| 442 | FormItineraryStageString(Name, ItinData, ItinStageString, NStages); |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 443 | |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 444 | // Get string and operand cycle count |
| 445 | std::string ItinOperandCycleString; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 446 | unsigned NOperandCycles = 0; |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 447 | std::string ItinBypassString; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 448 | if (ItinData) { |
| 449 | FormItineraryOperandCycleString(ItinData, ItinOperandCycleString, |
| 450 | NOperandCycles); |
| 451 | |
| 452 | FormItineraryBypassString(Name, ItinData, ItinBypassString, |
| 453 | NOperandCycles); |
| 454 | } |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 455 | |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 456 | // Check to see if stage already exists and create if it doesn't |
| 457 | unsigned FindStage = 0; |
| 458 | if (NStages > 0) { |
| 459 | FindStage = ItinStageMap[ItinStageString]; |
| 460 | if (FindStage == 0) { |
Andrew Trick | 8a05f66 | 2011-04-01 02:22:47 +0000 | [diff] [blame] | 461 | // Emit as { cycles, u1 | u2 | ... | un, timeinc }, // indices |
| 462 | StageTable += ItinStageString + ", // " + itostr(StageCount); |
| 463 | if (NStages > 1) |
| 464 | StageTable += "-" + itostr(StageCount + NStages - 1); |
| 465 | StageTable += "\n"; |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 466 | // Record Itin class number. |
| 467 | ItinStageMap[ItinStageString] = FindStage = StageCount; |
| 468 | StageCount += NStages; |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 469 | } |
| 470 | } |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 471 | |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 472 | // Check to see if operand cycle already exists and create if it doesn't |
| 473 | unsigned FindOperandCycle = 0; |
| 474 | if (NOperandCycles > 0) { |
Evan Cheng | 4a010fd | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 475 | std::string ItinOperandString = ItinOperandCycleString+ItinBypassString; |
| 476 | FindOperandCycle = ItinOperandMap[ItinOperandString]; |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 477 | if (FindOperandCycle == 0) { |
| 478 | // Emit as cycle, // index |
Andrew Trick | 8a05f66 | 2011-04-01 02:22:47 +0000 | [diff] [blame] | 479 | OperandCycleTable += ItinOperandCycleString + ", // "; |
| 480 | std::string OperandIdxComment = itostr(OperandCycleCount); |
| 481 | if (NOperandCycles > 1) |
| 482 | OperandIdxComment += "-" |
| 483 | + itostr(OperandCycleCount + NOperandCycles - 1); |
| 484 | OperandCycleTable += OperandIdxComment + "\n"; |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 485 | // Record Itin class number. |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 486 | ItinOperandMap[ItinOperandCycleString] = |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 487 | FindOperandCycle = OperandCycleCount; |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 488 | // Emit as bypass, // index |
Andrew Trick | 8a05f66 | 2011-04-01 02:22:47 +0000 | [diff] [blame] | 489 | BypassTable += ItinBypassString + ", // " + OperandIdxComment + "\n"; |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 490 | OperandCycleCount += NOperandCycles; |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 491 | } |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 492 | } |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 493 | |
Evan Cheng | 367a5df | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 494 | // Set up itinerary as location and location + stage count |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 495 | int NumUOps = ItinData ? ItinData->getValueAsInt("NumMicroOps") : 0; |
Evan Cheng | 367a5df | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 496 | InstrItinerary Intinerary = { NumUOps, FindStage, FindStage + NStages, |
| 497 | FindOperandCycle, |
| 498 | FindOperandCycle + NOperandCycles}; |
| 499 | |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 500 | // Inject - empty slots will be 0, 0 |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 501 | ItinList[SchedClassIdx] = Intinerary; |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 502 | } |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 503 | } |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 504 | |
Jim Laskey | d6d3afb | 2005-11-03 22:47:41 +0000 | [diff] [blame] | 505 | // Closing stage |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 506 | StageTable += " { 0, 0, 0, llvm::InstrStage::Required } // End stages\n"; |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 507 | StageTable += "};\n"; |
| 508 | |
| 509 | // Closing operand cycles |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 510 | OperandCycleTable += " 0 // End operand cycles\n"; |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 511 | OperandCycleTable += "};\n"; |
| 512 | |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 513 | BypassTable += " 0 // End bypass tables\n"; |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 514 | BypassTable += "};\n"; |
| 515 | |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 516 | // Emit tables. |
| 517 | OS << StageTable; |
| 518 | OS << OperandCycleTable; |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 519 | OS << BypassTable; |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 520 | } |
| 521 | |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 522 | // |
| 523 | // EmitProcessorData - Generate data for processor itineraries that were |
| 524 | // computed during EmitStageAndOperandCycleData(). ProcItinLists lists all |
| 525 | // Itineraries for each processor. The Itinerary lists are indexed on |
| 526 | // CodeGenSchedClass::Index. |
| 527 | // |
| 528 | void SubtargetEmitter:: |
| 529 | EmitItineraries(raw_ostream &OS, |
| 530 | std::vector<std::vector<InstrItinerary> > &ProcItinLists) { |
| 531 | |
Andrew Trick | fb982dd | 2012-07-09 20:43:03 +0000 | [diff] [blame] | 532 | // Multiple processor models may share an itinerary record. Emit it once. |
| 533 | SmallPtrSet<Record*, 8> ItinsDefSet; |
| 534 | |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 535 | // For each processor's machine model |
| 536 | std::vector<std::vector<InstrItinerary> >::iterator |
| 537 | ProcItinListsIter = ProcItinLists.begin(); |
| 538 | for (CodeGenSchedModels::ProcIter PI = SchedModels.procModelBegin(), |
Andrew Trick | 7668649 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 539 | PE = SchedModels.procModelEnd(); PI != PE; ++PI, ++ProcItinListsIter) { |
Andrew Trick | fb982dd | 2012-07-09 20:43:03 +0000 | [diff] [blame] | 540 | |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 541 | Record *ItinsDef = PI->ItinsDef; |
David Blaikie | 70573dc | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 542 | if (!ItinsDefSet.insert(ItinsDef).second) |
Andrew Trick | fb982dd | 2012-07-09 20:43:03 +0000 | [diff] [blame] | 543 | continue; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 544 | |
| 545 | // Get processor itinerary name |
| 546 | const std::string &Name = ItinsDef->getName(); |
| 547 | |
| 548 | // Get the itinerary list for the processor. |
| 549 | assert(ProcItinListsIter != ProcItinLists.end() && "bad iterator"); |
Andrew Trick | 7668649 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 550 | std::vector<InstrItinerary> &ItinList = *ProcItinListsIter; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 551 | |
Pete Cooper | c0eb153 | 2014-09-02 23:23:34 +0000 | [diff] [blame] | 552 | // Empty itineraries aren't referenced anywhere in the tablegen output |
| 553 | // so don't emit them. |
| 554 | if (ItinList.empty()) |
| 555 | continue; |
| 556 | |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 557 | OS << "\n"; |
| 558 | OS << "static const llvm::InstrItinerary "; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 559 | |
| 560 | // Begin processor itinerary table |
| 561 | OS << Name << "[] = {\n"; |
| 562 | |
| 563 | // For each itinerary class in CodeGenSchedClass::Index order. |
| 564 | for (unsigned j = 0, M = ItinList.size(); j < M; ++j) { |
| 565 | InstrItinerary &Intinerary = ItinList[j]; |
| 566 | |
| 567 | // Emit Itinerary in the form of |
| 568 | // { firstStage, lastStage, firstCycle, lastCycle } // index |
| 569 | OS << " { " << |
| 570 | Intinerary.NumMicroOps << ", " << |
| 571 | Intinerary.FirstStage << ", " << |
| 572 | Intinerary.LastStage << ", " << |
| 573 | Intinerary.FirstOperandCycle << ", " << |
| 574 | Intinerary.LastOperandCycle << " }" << |
| 575 | ", // " << j << " " << SchedModels.getSchedClass(j).Name << "\n"; |
| 576 | } |
| 577 | // End processor itinerary table |
| 578 | OS << " { 0, ~0U, ~0U, ~0U, ~0U } // end marker\n"; |
| 579 | OS << "};\n"; |
| 580 | } |
| 581 | } |
| 582 | |
Sylvestre Ledru | 35521e2 | 2012-07-23 08:51:15 +0000 | [diff] [blame] | 583 | // Emit either the value defined in the TableGen Record, or the default |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 584 | // value defined in the C++ header. The Record is null if the processor does not |
| 585 | // define a model. |
| 586 | void SubtargetEmitter::EmitProcessorProp(raw_ostream &OS, const Record *R, |
Andrew Trick | 73d7736 | 2012-06-05 03:44:40 +0000 | [diff] [blame] | 587 | const char *Name, char Separator) { |
| 588 | OS << " "; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 589 | int V = R ? R->getValueAsInt(Name) : -1; |
Andrew Trick | 73d7736 | 2012-06-05 03:44:40 +0000 | [diff] [blame] | 590 | if (V >= 0) |
| 591 | OS << V << Separator << " // " << Name; |
| 592 | else |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 593 | OS << "MCSchedModel::Default" << Name << Separator; |
Andrew Trick | 73d7736 | 2012-06-05 03:44:40 +0000 | [diff] [blame] | 594 | OS << '\n'; |
| 595 | } |
| 596 | |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 597 | void SubtargetEmitter::EmitProcessorResources(const CodeGenProcModel &ProcModel, |
| 598 | raw_ostream &OS) { |
| 599 | char Sep = ProcModel.ProcResourceDefs.empty() ? ' ' : ','; |
| 600 | |
Andrew Trick | 8e9c1d8 | 2012-10-10 05:43:04 +0000 | [diff] [blame] | 601 | OS << "\n// {Name, NumUnits, SuperIdx, IsBuffered}\n"; |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 602 | OS << "static const llvm::MCProcResourceDesc " |
| 603 | << ProcModel.ModelName << "ProcResources" << "[] = {\n" |
Andrew Trick | 8e9c1d8 | 2012-10-10 05:43:04 +0000 | [diff] [blame] | 604 | << " {DBGFIELD(\"InvalidUnit\") 0, 0, 0}" << Sep << "\n"; |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 605 | |
| 606 | for (unsigned i = 0, e = ProcModel.ProcResourceDefs.size(); i < e; ++i) { |
| 607 | Record *PRDef = ProcModel.ProcResourceDefs[i]; |
| 608 | |
Craig Topper | 2406477 | 2014-04-15 07:20:03 +0000 | [diff] [blame] | 609 | Record *SuperDef = nullptr; |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 610 | unsigned SuperIdx = 0; |
| 611 | unsigned NumUnits = 0; |
Andrew Trick | 40c4f38 | 2013-06-15 04:50:06 +0000 | [diff] [blame] | 612 | int BufferSize = PRDef->getValueAsInt("BufferSize"); |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 613 | if (PRDef->isSubClassOf("ProcResGroup")) { |
| 614 | RecVec ResUnits = PRDef->getValueAsListOfDefs("Resources"); |
| 615 | for (RecIter RUI = ResUnits.begin(), RUE = ResUnits.end(); |
| 616 | RUI != RUE; ++RUI) { |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 617 | NumUnits += (*RUI)->getValueAsInt("NumUnits"); |
| 618 | } |
| 619 | } |
| 620 | else { |
| 621 | // Find the SuperIdx |
| 622 | if (PRDef->getValueInit("Super")->isComplete()) { |
| 623 | SuperDef = SchedModels.findProcResUnits( |
| 624 | PRDef->getValueAsDef("Super"), ProcModel); |
| 625 | SuperIdx = ProcModel.getProcResourceIdx(SuperDef); |
| 626 | } |
Andrew Trick | a5c747b | 2013-03-14 22:47:01 +0000 | [diff] [blame] | 627 | NumUnits = PRDef->getValueAsInt("NumUnits"); |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 628 | } |
| 629 | // Emit the ProcResourceDesc |
| 630 | if (i+1 == e) |
| 631 | Sep = ' '; |
| 632 | OS << " {DBGFIELD(\"" << PRDef->getName() << "\") "; |
| 633 | if (PRDef->getName().size() < 15) |
| 634 | OS.indent(15 - PRDef->getName().size()); |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 635 | OS << NumUnits << ", " << SuperIdx << ", " |
Andrew Trick | de2109e | 2013-06-15 04:49:57 +0000 | [diff] [blame] | 636 | << BufferSize << "}" << Sep << " // #" << i+1; |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 637 | if (SuperDef) |
| 638 | OS << ", Super=" << SuperDef->getName(); |
| 639 | OS << "\n"; |
| 640 | } |
| 641 | OS << "};\n"; |
| 642 | } |
| 643 | |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 644 | // Find the WriteRes Record that defines processor resources for this |
| 645 | // SchedWrite. |
| 646 | Record *SubtargetEmitter::FindWriteResources( |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 647 | const CodeGenSchedRW &SchedWrite, const CodeGenProcModel &ProcModel) { |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 648 | |
| 649 | // Check if the SchedWrite is already subtarget-specific and directly |
| 650 | // specifies a set of processor resources. |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 651 | if (SchedWrite.TheDef->isSubClassOf("SchedWriteRes")) |
| 652 | return SchedWrite.TheDef; |
| 653 | |
Craig Topper | 2406477 | 2014-04-15 07:20:03 +0000 | [diff] [blame] | 654 | Record *AliasDef = nullptr; |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 655 | for (RecIter AI = SchedWrite.Aliases.begin(), AE = SchedWrite.Aliases.end(); |
| 656 | AI != AE; ++AI) { |
| 657 | const CodeGenSchedRW &AliasRW = |
| 658 | SchedModels.getSchedRW((*AI)->getValueAsDef("AliasRW")); |
Andrew Trick | da984b1 | 2012-10-03 23:06:28 +0000 | [diff] [blame] | 659 | if (AliasRW.TheDef->getValueInit("SchedModel")->isComplete()) { |
| 660 | Record *ModelDef = AliasRW.TheDef->getValueAsDef("SchedModel"); |
| 661 | if (&SchedModels.getProcModel(ModelDef) != &ProcModel) |
| 662 | continue; |
| 663 | } |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 664 | if (AliasDef) |
Joerg Sonnenberger | 635debe | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 665 | PrintFatalError(AliasRW.TheDef->getLoc(), "Multiple aliases " |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 666 | "defined for processor " + ProcModel.ModelName + |
| 667 | " Ensure only one SchedAlias exists per RW."); |
| 668 | AliasDef = AliasRW.TheDef; |
| 669 | } |
| 670 | if (AliasDef && AliasDef->isSubClassOf("SchedWriteRes")) |
| 671 | return AliasDef; |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 672 | |
| 673 | // Check this processor's list of write resources. |
Craig Topper | 2406477 | 2014-04-15 07:20:03 +0000 | [diff] [blame] | 674 | Record *ResDef = nullptr; |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 675 | for (RecIter WRI = ProcModel.WriteResDefs.begin(), |
| 676 | WRE = ProcModel.WriteResDefs.end(); WRI != WRE; ++WRI) { |
| 677 | if (!(*WRI)->isSubClassOf("WriteRes")) |
| 678 | continue; |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 679 | if (AliasDef == (*WRI)->getValueAsDef("WriteType") |
| 680 | || SchedWrite.TheDef == (*WRI)->getValueAsDef("WriteType")) { |
| 681 | if (ResDef) { |
Joerg Sonnenberger | 635debe | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 682 | PrintFatalError((*WRI)->getLoc(), "Resources are defined for both " |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 683 | "SchedWrite and its alias on processor " + |
| 684 | ProcModel.ModelName); |
| 685 | } |
| 686 | ResDef = *WRI; |
| 687 | } |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 688 | } |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 689 | // TODO: If ProcModel has a base model (previous generation processor), |
| 690 | // then call FindWriteResources recursively with that model here. |
| 691 | if (!ResDef) { |
Joerg Sonnenberger | 635debe | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 692 | PrintFatalError(ProcModel.ModelDef->getLoc(), |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 693 | std::string("Processor does not define resources for ") |
| 694 | + SchedWrite.TheDef->getName()); |
| 695 | } |
| 696 | return ResDef; |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | /// Find the ReadAdvance record for the given SchedRead on this processor or |
| 700 | /// return NULL. |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 701 | Record *SubtargetEmitter::FindReadAdvance(const CodeGenSchedRW &SchedRead, |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 702 | const CodeGenProcModel &ProcModel) { |
| 703 | // Check for SchedReads that directly specify a ReadAdvance. |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 704 | if (SchedRead.TheDef->isSubClassOf("SchedReadAdvance")) |
| 705 | return SchedRead.TheDef; |
| 706 | |
| 707 | // Check this processor's list of aliases for SchedRead. |
Craig Topper | 2406477 | 2014-04-15 07:20:03 +0000 | [diff] [blame] | 708 | Record *AliasDef = nullptr; |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 709 | for (RecIter AI = SchedRead.Aliases.begin(), AE = SchedRead.Aliases.end(); |
| 710 | AI != AE; ++AI) { |
| 711 | const CodeGenSchedRW &AliasRW = |
| 712 | SchedModels.getSchedRW((*AI)->getValueAsDef("AliasRW")); |
Andrew Trick | da984b1 | 2012-10-03 23:06:28 +0000 | [diff] [blame] | 713 | if (AliasRW.TheDef->getValueInit("SchedModel")->isComplete()) { |
| 714 | Record *ModelDef = AliasRW.TheDef->getValueAsDef("SchedModel"); |
| 715 | if (&SchedModels.getProcModel(ModelDef) != &ProcModel) |
| 716 | continue; |
| 717 | } |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 718 | if (AliasDef) |
Joerg Sonnenberger | 635debe | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 719 | PrintFatalError(AliasRW.TheDef->getLoc(), "Multiple aliases " |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 720 | "defined for processor " + ProcModel.ModelName + |
| 721 | " Ensure only one SchedAlias exists per RW."); |
| 722 | AliasDef = AliasRW.TheDef; |
| 723 | } |
| 724 | if (AliasDef && AliasDef->isSubClassOf("SchedReadAdvance")) |
| 725 | return AliasDef; |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 726 | |
| 727 | // Check this processor's ReadAdvanceList. |
Craig Topper | 2406477 | 2014-04-15 07:20:03 +0000 | [diff] [blame] | 728 | Record *ResDef = nullptr; |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 729 | for (RecIter RAI = ProcModel.ReadAdvanceDefs.begin(), |
| 730 | RAE = ProcModel.ReadAdvanceDefs.end(); RAI != RAE; ++RAI) { |
| 731 | if (!(*RAI)->isSubClassOf("ReadAdvance")) |
| 732 | continue; |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 733 | if (AliasDef == (*RAI)->getValueAsDef("ReadType") |
| 734 | || SchedRead.TheDef == (*RAI)->getValueAsDef("ReadType")) { |
| 735 | if (ResDef) { |
Joerg Sonnenberger | 635debe | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 736 | PrintFatalError((*RAI)->getLoc(), "Resources are defined for both " |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 737 | "SchedRead and its alias on processor " + |
| 738 | ProcModel.ModelName); |
| 739 | } |
| 740 | ResDef = *RAI; |
| 741 | } |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 742 | } |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 743 | // TODO: If ProcModel has a base model (previous generation processor), |
| 744 | // then call FindReadAdvance recursively with that model here. |
| 745 | if (!ResDef && SchedRead.TheDef->getName() != "ReadDefault") { |
Joerg Sonnenberger | 635debe | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 746 | PrintFatalError(ProcModel.ModelDef->getLoc(), |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 747 | std::string("Processor does not define resources for ") |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 748 | + SchedRead.TheDef->getName()); |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 749 | } |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 750 | return ResDef; |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 751 | } |
| 752 | |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 753 | // Expand an explicit list of processor resources into a full list of implied |
Andrew Trick | a3801a3 | 2013-04-23 23:45:16 +0000 | [diff] [blame] | 754 | // resource groups and super resources that cover them. |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 755 | void SubtargetEmitter::ExpandProcResources(RecVec &PRVec, |
| 756 | std::vector<int64_t> &Cycles, |
Andrew Trick | a3801a3 | 2013-04-23 23:45:16 +0000 | [diff] [blame] | 757 | const CodeGenProcModel &PM) { |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 758 | // Default to 1 resource cycle. |
| 759 | Cycles.resize(PRVec.size(), 1); |
| 760 | for (unsigned i = 0, e = PRVec.size(); i != e; ++i) { |
Andrew Trick | a3801a3 | 2013-04-23 23:45:16 +0000 | [diff] [blame] | 761 | Record *PRDef = PRVec[i]; |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 762 | RecVec SubResources; |
Andrew Trick | a3801a3 | 2013-04-23 23:45:16 +0000 | [diff] [blame] | 763 | if (PRDef->isSubClassOf("ProcResGroup")) |
| 764 | SubResources = PRDef->getValueAsListOfDefs("Resources"); |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 765 | else { |
Andrew Trick | a3801a3 | 2013-04-23 23:45:16 +0000 | [diff] [blame] | 766 | SubResources.push_back(PRDef); |
| 767 | PRDef = SchedModels.findProcResUnits(PRVec[i], PM); |
| 768 | for (Record *SubDef = PRDef; |
| 769 | SubDef->getValueInit("Super")->isComplete();) { |
| 770 | if (SubDef->isSubClassOf("ProcResGroup")) { |
| 771 | // Disallow this for simplicitly. |
| 772 | PrintFatalError(SubDef->getLoc(), "Processor resource group " |
| 773 | " cannot be a super resources."); |
| 774 | } |
| 775 | Record *SuperDef = |
| 776 | SchedModels.findProcResUnits(SubDef->getValueAsDef("Super"), PM); |
| 777 | PRVec.push_back(SuperDef); |
| 778 | Cycles.push_back(Cycles[i]); |
| 779 | SubDef = SuperDef; |
| 780 | } |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 781 | } |
Andrew Trick | a3801a3 | 2013-04-23 23:45:16 +0000 | [diff] [blame] | 782 | for (RecIter PRI = PM.ProcResourceDefs.begin(), |
| 783 | PRE = PM.ProcResourceDefs.end(); |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 784 | PRI != PRE; ++PRI) { |
Andrew Trick | a3801a3 | 2013-04-23 23:45:16 +0000 | [diff] [blame] | 785 | if (*PRI == PRDef || !(*PRI)->isSubClassOf("ProcResGroup")) |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 786 | continue; |
| 787 | RecVec SuperResources = (*PRI)->getValueAsListOfDefs("Resources"); |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 788 | RecIter SubI = SubResources.begin(), SubE = SubResources.end(); |
Andrew Trick | 6aa7a87 | 2013-04-23 23:45:11 +0000 | [diff] [blame] | 789 | for( ; SubI != SubE; ++SubI) { |
| 790 | if (std::find(SuperResources.begin(), SuperResources.end(), *SubI) |
| 791 | == SuperResources.end()) { |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 792 | break; |
Andrew Trick | 6aa7a87 | 2013-04-23 23:45:11 +0000 | [diff] [blame] | 793 | } |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 794 | } |
| 795 | if (SubI == SubE) { |
| 796 | PRVec.push_back(*PRI); |
| 797 | Cycles.push_back(Cycles[i]); |
| 798 | } |
| 799 | } |
| 800 | } |
| 801 | } |
| 802 | |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 803 | // Generate the SchedClass table for this processor and update global |
| 804 | // tables. Must be called for each processor in order. |
| 805 | void SubtargetEmitter::GenSchedClassTables(const CodeGenProcModel &ProcModel, |
| 806 | SchedClassTables &SchedTables) { |
| 807 | SchedTables.ProcSchedClasses.resize(SchedTables.ProcSchedClasses.size() + 1); |
| 808 | if (!ProcModel.hasInstrSchedModel()) |
| 809 | return; |
| 810 | |
| 811 | std::vector<MCSchedClassDesc> &SCTab = SchedTables.ProcSchedClasses.back(); |
| 812 | for (CodeGenSchedModels::SchedClassIter SCI = SchedModels.schedClassBegin(), |
| 813 | SCE = SchedModels.schedClassEnd(); SCI != SCE; ++SCI) { |
Andrew Trick | 7aba6be | 2012-10-03 23:06:25 +0000 | [diff] [blame] | 814 | DEBUG(SCI->dump(&SchedModels)); |
| 815 | |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 816 | SCTab.resize(SCTab.size() + 1); |
| 817 | MCSchedClassDesc &SCDesc = SCTab.back(); |
Andrew Trick | ab722bd | 2012-09-18 03:18:56 +0000 | [diff] [blame] | 818 | // SCDesc.Name is guarded by NDEBUG |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 819 | SCDesc.NumMicroOps = 0; |
| 820 | SCDesc.BeginGroup = false; |
| 821 | SCDesc.EndGroup = false; |
| 822 | SCDesc.WriteProcResIdx = 0; |
| 823 | SCDesc.WriteLatencyIdx = 0; |
| 824 | SCDesc.ReadAdvanceIdx = 0; |
| 825 | |
| 826 | // A Variant SchedClass has no resources of its own. |
Andrew Trick | e97978f | 2013-03-26 21:36:39 +0000 | [diff] [blame] | 827 | bool HasVariants = false; |
| 828 | for (std::vector<CodeGenSchedTransition>::const_iterator |
| 829 | TI = SCI->Transitions.begin(), TE = SCI->Transitions.end(); |
| 830 | TI != TE; ++TI) { |
| 831 | if (TI->ProcIndices[0] == 0) { |
| 832 | HasVariants = true; |
| 833 | break; |
| 834 | } |
| 835 | IdxIter PIPos = std::find(TI->ProcIndices.begin(), |
| 836 | TI->ProcIndices.end(), ProcModel.Index); |
| 837 | if (PIPos != TI->ProcIndices.end()) { |
| 838 | HasVariants = true; |
| 839 | break; |
| 840 | } |
| 841 | } |
| 842 | if (HasVariants) { |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 843 | SCDesc.NumMicroOps = MCSchedClassDesc::VariantNumMicroOps; |
| 844 | continue; |
| 845 | } |
| 846 | |
| 847 | // Determine if the SchedClass is actually reachable on this processor. If |
| 848 | // not don't try to locate the processor resources, it will fail. |
| 849 | // If ProcIndices contains 0, this class applies to all processors. |
| 850 | assert(!SCI->ProcIndices.empty() && "expect at least one procidx"); |
| 851 | if (SCI->ProcIndices[0] != 0) { |
| 852 | IdxIter PIPos = std::find(SCI->ProcIndices.begin(), |
| 853 | SCI->ProcIndices.end(), ProcModel.Index); |
| 854 | if (PIPos == SCI->ProcIndices.end()) |
| 855 | continue; |
| 856 | } |
| 857 | IdxVec Writes = SCI->Writes; |
| 858 | IdxVec Reads = SCI->Reads; |
Andrew Trick | bf8a28d | 2013-03-16 18:58:55 +0000 | [diff] [blame] | 859 | if (!SCI->InstRWs.empty()) { |
| 860 | // This class has a default ReadWrite list which can be overriden by |
Andrew Trick | 7aba6be | 2012-10-03 23:06:25 +0000 | [diff] [blame] | 861 | // InstRW definitions. |
Craig Topper | 2406477 | 2014-04-15 07:20:03 +0000 | [diff] [blame] | 862 | Record *RWDef = nullptr; |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 863 | for (RecIter RWI = SCI->InstRWs.begin(), RWE = SCI->InstRWs.end(); |
| 864 | RWI != RWE; ++RWI) { |
| 865 | Record *RWModelDef = (*RWI)->getValueAsDef("SchedModel"); |
| 866 | if (&ProcModel == &SchedModels.getProcModel(RWModelDef)) { |
| 867 | RWDef = *RWI; |
| 868 | break; |
| 869 | } |
| 870 | } |
| 871 | if (RWDef) { |
Andrew Trick | da984b1 | 2012-10-03 23:06:28 +0000 | [diff] [blame] | 872 | Writes.clear(); |
| 873 | Reads.clear(); |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 874 | SchedModels.findRWs(RWDef->getValueAsListOfDefs("OperandReadWrites"), |
| 875 | Writes, Reads); |
| 876 | } |
| 877 | } |
Andrew Trick | bf8a28d | 2013-03-16 18:58:55 +0000 | [diff] [blame] | 878 | if (Writes.empty()) { |
| 879 | // Check this processor's itinerary class resources. |
| 880 | for (RecIter II = ProcModel.ItinRWDefs.begin(), |
| 881 | IE = ProcModel.ItinRWDefs.end(); II != IE; ++II) { |
| 882 | RecVec Matched = (*II)->getValueAsListOfDefs("MatchedItinClasses"); |
| 883 | if (std::find(Matched.begin(), Matched.end(), SCI->ItinClassDef) |
| 884 | != Matched.end()) { |
| 885 | SchedModels.findRWs((*II)->getValueAsListOfDefs("OperandReadWrites"), |
| 886 | Writes, Reads); |
| 887 | break; |
| 888 | } |
| 889 | } |
| 890 | if (Writes.empty()) { |
| 891 | DEBUG(dbgs() << ProcModel.ModelName |
| 892 | << " does not have resources for class " << SCI->Name << '\n'); |
| 893 | } |
| 894 | } |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 895 | // Sum resources across all operand writes. |
| 896 | std::vector<MCWriteProcResEntry> WriteProcResources; |
| 897 | std::vector<MCWriteLatencyEntry> WriteLatencies; |
Andrew Trick | cfe222c | 2012-09-19 04:43:19 +0000 | [diff] [blame] | 898 | std::vector<std::string> WriterNames; |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 899 | std::vector<MCReadAdvanceEntry> ReadAdvanceEntries; |
| 900 | for (IdxIter WI = Writes.begin(), WE = Writes.end(); WI != WE; ++WI) { |
| 901 | IdxVec WriteSeq; |
Andrew Trick | da984b1 | 2012-10-03 23:06:28 +0000 | [diff] [blame] | 902 | SchedModels.expandRWSeqForProc(*WI, WriteSeq, /*IsRead=*/false, |
| 903 | ProcModel); |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 904 | |
| 905 | // For each operand, create a latency entry. |
| 906 | MCWriteLatencyEntry WLEntry; |
| 907 | WLEntry.Cycles = 0; |
Andrew Trick | cfe222c | 2012-09-19 04:43:19 +0000 | [diff] [blame] | 908 | unsigned WriteID = WriteSeq.back(); |
| 909 | WriterNames.push_back(SchedModels.getSchedWrite(WriteID).Name); |
| 910 | // If this Write is not referenced by a ReadAdvance, don't distinguish it |
| 911 | // from other WriteLatency entries. |
Andrew Trick | bf8a28d | 2013-03-16 18:58:55 +0000 | [diff] [blame] | 912 | if (!SchedModels.hasReadOfWrite( |
| 913 | SchedModels.getSchedWrite(WriteID).TheDef)) { |
Andrew Trick | cfe222c | 2012-09-19 04:43:19 +0000 | [diff] [blame] | 914 | WriteID = 0; |
| 915 | } |
| 916 | WLEntry.WriteResourceID = WriteID; |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 917 | |
| 918 | for (IdxIter WSI = WriteSeq.begin(), WSE = WriteSeq.end(); |
| 919 | WSI != WSE; ++WSI) { |
| 920 | |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 921 | Record *WriteRes = |
| 922 | FindWriteResources(SchedModels.getSchedWrite(*WSI), ProcModel); |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 923 | |
| 924 | // Mark the parent class as invalid for unsupported write types. |
| 925 | if (WriteRes->getValueAsBit("Unsupported")) { |
| 926 | SCDesc.NumMicroOps = MCSchedClassDesc::InvalidNumMicroOps; |
| 927 | break; |
| 928 | } |
| 929 | WLEntry.Cycles += WriteRes->getValueAsInt("Latency"); |
| 930 | SCDesc.NumMicroOps += WriteRes->getValueAsInt("NumMicroOps"); |
| 931 | SCDesc.BeginGroup |= WriteRes->getValueAsBit("BeginGroup"); |
| 932 | SCDesc.EndGroup |= WriteRes->getValueAsBit("EndGroup"); |
| 933 | |
| 934 | // Create an entry for each ProcResource listed in WriteRes. |
| 935 | RecVec PRVec = WriteRes->getValueAsListOfDefs("ProcResources"); |
| 936 | std::vector<int64_t> Cycles = |
| 937 | WriteRes->getValueAsListOfInts("ResourceCycles"); |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 938 | |
| 939 | ExpandProcResources(PRVec, Cycles, ProcModel); |
| 940 | |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 941 | for (unsigned PRIdx = 0, PREnd = PRVec.size(); |
| 942 | PRIdx != PREnd; ++PRIdx) { |
| 943 | MCWriteProcResEntry WPREntry; |
| 944 | WPREntry.ProcResourceIdx = ProcModel.getProcResourceIdx(PRVec[PRIdx]); |
| 945 | assert(WPREntry.ProcResourceIdx && "Bad ProcResourceIdx"); |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 946 | WPREntry.Cycles = Cycles[PRIdx]; |
Andrew Trick | 3821d9d | 2013-03-01 23:31:26 +0000 | [diff] [blame] | 947 | // If this resource is already used in this sequence, add the current |
| 948 | // entry's cycles so that the same resource appears to be used |
| 949 | // serially, rather than multiple parallel uses. This is important for |
| 950 | // in-order machine where the resource consumption is a hazard. |
| 951 | unsigned WPRIdx = 0, WPREnd = WriteProcResources.size(); |
| 952 | for( ; WPRIdx != WPREnd; ++WPRIdx) { |
| 953 | if (WriteProcResources[WPRIdx].ProcResourceIdx |
| 954 | == WPREntry.ProcResourceIdx) { |
| 955 | WriteProcResources[WPRIdx].Cycles += WPREntry.Cycles; |
| 956 | break; |
| 957 | } |
| 958 | } |
| 959 | if (WPRIdx == WPREnd) |
| 960 | WriteProcResources.push_back(WPREntry); |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 961 | } |
| 962 | } |
| 963 | WriteLatencies.push_back(WLEntry); |
| 964 | } |
| 965 | // Create an entry for each operand Read in this SchedClass. |
| 966 | // Entries must be sorted first by UseIdx then by WriteResourceID. |
| 967 | for (unsigned UseIdx = 0, EndIdx = Reads.size(); |
| 968 | UseIdx != EndIdx; ++UseIdx) { |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 969 | Record *ReadAdvance = |
| 970 | FindReadAdvance(SchedModels.getSchedRead(Reads[UseIdx]), ProcModel); |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 971 | if (!ReadAdvance) |
| 972 | continue; |
| 973 | |
| 974 | // Mark the parent class as invalid for unsupported write types. |
| 975 | if (ReadAdvance->getValueAsBit("Unsupported")) { |
| 976 | SCDesc.NumMicroOps = MCSchedClassDesc::InvalidNumMicroOps; |
| 977 | break; |
| 978 | } |
| 979 | RecVec ValidWrites = ReadAdvance->getValueAsListOfDefs("ValidWrites"); |
| 980 | IdxVec WriteIDs; |
| 981 | if (ValidWrites.empty()) |
| 982 | WriteIDs.push_back(0); |
| 983 | else { |
| 984 | for (RecIter VWI = ValidWrites.begin(), VWE = ValidWrites.end(); |
| 985 | VWI != VWE; ++VWI) { |
| 986 | WriteIDs.push_back(SchedModels.getSchedRWIdx(*VWI, /*IsRead=*/false)); |
| 987 | } |
| 988 | } |
| 989 | std::sort(WriteIDs.begin(), WriteIDs.end()); |
| 990 | for(IdxIter WI = WriteIDs.begin(), WE = WriteIDs.end(); WI != WE; ++WI) { |
| 991 | MCReadAdvanceEntry RAEntry; |
| 992 | RAEntry.UseIdx = UseIdx; |
| 993 | RAEntry.WriteResourceID = *WI; |
| 994 | RAEntry.Cycles = ReadAdvance->getValueAsInt("Cycles"); |
| 995 | ReadAdvanceEntries.push_back(RAEntry); |
| 996 | } |
| 997 | } |
| 998 | if (SCDesc.NumMicroOps == MCSchedClassDesc::InvalidNumMicroOps) { |
| 999 | WriteProcResources.clear(); |
| 1000 | WriteLatencies.clear(); |
| 1001 | ReadAdvanceEntries.clear(); |
| 1002 | } |
| 1003 | // Add the information for this SchedClass to the global tables using basic |
| 1004 | // compression. |
| 1005 | // |
| 1006 | // WritePrecRes entries are sorted by ProcResIdx. |
| 1007 | std::sort(WriteProcResources.begin(), WriteProcResources.end(), |
| 1008 | LessWriteProcResources()); |
| 1009 | |
| 1010 | SCDesc.NumWriteProcResEntries = WriteProcResources.size(); |
| 1011 | std::vector<MCWriteProcResEntry>::iterator WPRPos = |
| 1012 | std::search(SchedTables.WriteProcResources.begin(), |
| 1013 | SchedTables.WriteProcResources.end(), |
| 1014 | WriteProcResources.begin(), WriteProcResources.end()); |
| 1015 | if (WPRPos != SchedTables.WriteProcResources.end()) |
| 1016 | SCDesc.WriteProcResIdx = WPRPos - SchedTables.WriteProcResources.begin(); |
| 1017 | else { |
| 1018 | SCDesc.WriteProcResIdx = SchedTables.WriteProcResources.size(); |
| 1019 | SchedTables.WriteProcResources.insert(WPRPos, WriteProcResources.begin(), |
| 1020 | WriteProcResources.end()); |
| 1021 | } |
| 1022 | // Latency entries must remain in operand order. |
| 1023 | SCDesc.NumWriteLatencyEntries = WriteLatencies.size(); |
| 1024 | std::vector<MCWriteLatencyEntry>::iterator WLPos = |
| 1025 | std::search(SchedTables.WriteLatencies.begin(), |
| 1026 | SchedTables.WriteLatencies.end(), |
| 1027 | WriteLatencies.begin(), WriteLatencies.end()); |
Andrew Trick | cfe222c | 2012-09-19 04:43:19 +0000 | [diff] [blame] | 1028 | if (WLPos != SchedTables.WriteLatencies.end()) { |
| 1029 | unsigned idx = WLPos - SchedTables.WriteLatencies.begin(); |
| 1030 | SCDesc.WriteLatencyIdx = idx; |
| 1031 | for (unsigned i = 0, e = WriteLatencies.size(); i < e; ++i) |
| 1032 | if (SchedTables.WriterNames[idx + i].find(WriterNames[i]) == |
| 1033 | std::string::npos) { |
| 1034 | SchedTables.WriterNames[idx + i] += std::string("_") + WriterNames[i]; |
| 1035 | } |
| 1036 | } |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1037 | else { |
| 1038 | SCDesc.WriteLatencyIdx = SchedTables.WriteLatencies.size(); |
Andrew Trick | cfe222c | 2012-09-19 04:43:19 +0000 | [diff] [blame] | 1039 | SchedTables.WriteLatencies.insert(SchedTables.WriteLatencies.end(), |
| 1040 | WriteLatencies.begin(), |
| 1041 | WriteLatencies.end()); |
| 1042 | SchedTables.WriterNames.insert(SchedTables.WriterNames.end(), |
| 1043 | WriterNames.begin(), WriterNames.end()); |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1044 | } |
| 1045 | // ReadAdvanceEntries must remain in operand order. |
| 1046 | SCDesc.NumReadAdvanceEntries = ReadAdvanceEntries.size(); |
| 1047 | std::vector<MCReadAdvanceEntry>::iterator RAPos = |
| 1048 | std::search(SchedTables.ReadAdvanceEntries.begin(), |
| 1049 | SchedTables.ReadAdvanceEntries.end(), |
| 1050 | ReadAdvanceEntries.begin(), ReadAdvanceEntries.end()); |
| 1051 | if (RAPos != SchedTables.ReadAdvanceEntries.end()) |
| 1052 | SCDesc.ReadAdvanceIdx = RAPos - SchedTables.ReadAdvanceEntries.begin(); |
| 1053 | else { |
| 1054 | SCDesc.ReadAdvanceIdx = SchedTables.ReadAdvanceEntries.size(); |
| 1055 | SchedTables.ReadAdvanceEntries.insert(RAPos, ReadAdvanceEntries.begin(), |
| 1056 | ReadAdvanceEntries.end()); |
| 1057 | } |
| 1058 | } |
| 1059 | } |
| 1060 | |
Andrew Trick | a72fca6 | 2012-09-17 22:18:50 +0000 | [diff] [blame] | 1061 | // Emit SchedClass tables for all processors and associated global tables. |
| 1062 | void SubtargetEmitter::EmitSchedClassTables(SchedClassTables &SchedTables, |
| 1063 | raw_ostream &OS) { |
| 1064 | // Emit global WriteProcResTable. |
| 1065 | OS << "\n// {ProcResourceIdx, Cycles}\n" |
| 1066 | << "extern const llvm::MCWriteProcResEntry " |
| 1067 | << Target << "WriteProcResTable[] = {\n" |
| 1068 | << " { 0, 0}, // Invalid\n"; |
| 1069 | for (unsigned WPRIdx = 1, WPREnd = SchedTables.WriteProcResources.size(); |
| 1070 | WPRIdx != WPREnd; ++WPRIdx) { |
| 1071 | MCWriteProcResEntry &WPREntry = SchedTables.WriteProcResources[WPRIdx]; |
| 1072 | OS << " {" << format("%2d", WPREntry.ProcResourceIdx) << ", " |
| 1073 | << format("%2d", WPREntry.Cycles) << "}"; |
| 1074 | if (WPRIdx + 1 < WPREnd) |
| 1075 | OS << ','; |
| 1076 | OS << " // #" << WPRIdx << '\n'; |
| 1077 | } |
| 1078 | OS << "}; // " << Target << "WriteProcResTable\n"; |
| 1079 | |
| 1080 | // Emit global WriteLatencyTable. |
| 1081 | OS << "\n// {Cycles, WriteResourceID}\n" |
| 1082 | << "extern const llvm::MCWriteLatencyEntry " |
| 1083 | << Target << "WriteLatencyTable[] = {\n" |
| 1084 | << " { 0, 0}, // Invalid\n"; |
| 1085 | for (unsigned WLIdx = 1, WLEnd = SchedTables.WriteLatencies.size(); |
| 1086 | WLIdx != WLEnd; ++WLIdx) { |
| 1087 | MCWriteLatencyEntry &WLEntry = SchedTables.WriteLatencies[WLIdx]; |
| 1088 | OS << " {" << format("%2d", WLEntry.Cycles) << ", " |
| 1089 | << format("%2d", WLEntry.WriteResourceID) << "}"; |
| 1090 | if (WLIdx + 1 < WLEnd) |
| 1091 | OS << ','; |
Andrew Trick | cfe222c | 2012-09-19 04:43:19 +0000 | [diff] [blame] | 1092 | OS << " // #" << WLIdx << " " << SchedTables.WriterNames[WLIdx] << '\n'; |
Andrew Trick | a72fca6 | 2012-09-17 22:18:50 +0000 | [diff] [blame] | 1093 | } |
| 1094 | OS << "}; // " << Target << "WriteLatencyTable\n"; |
| 1095 | |
| 1096 | // Emit global ReadAdvanceTable. |
| 1097 | OS << "\n// {UseIdx, WriteResourceID, Cycles}\n" |
| 1098 | << "extern const llvm::MCReadAdvanceEntry " |
| 1099 | << Target << "ReadAdvanceTable[] = {\n" |
| 1100 | << " {0, 0, 0}, // Invalid\n"; |
| 1101 | for (unsigned RAIdx = 1, RAEnd = SchedTables.ReadAdvanceEntries.size(); |
| 1102 | RAIdx != RAEnd; ++RAIdx) { |
| 1103 | MCReadAdvanceEntry &RAEntry = SchedTables.ReadAdvanceEntries[RAIdx]; |
| 1104 | OS << " {" << RAEntry.UseIdx << ", " |
| 1105 | << format("%2d", RAEntry.WriteResourceID) << ", " |
| 1106 | << format("%2d", RAEntry.Cycles) << "}"; |
| 1107 | if (RAIdx + 1 < RAEnd) |
| 1108 | OS << ','; |
| 1109 | OS << " // #" << RAIdx << '\n'; |
| 1110 | } |
| 1111 | OS << "}; // " << Target << "ReadAdvanceTable\n"; |
| 1112 | |
| 1113 | // Emit a SchedClass table for each processor. |
| 1114 | for (CodeGenSchedModels::ProcIter PI = SchedModels.procModelBegin(), |
| 1115 | PE = SchedModels.procModelEnd(); PI != PE; ++PI) { |
| 1116 | if (!PI->hasInstrSchedModel()) |
| 1117 | continue; |
| 1118 | |
| 1119 | std::vector<MCSchedClassDesc> &SCTab = |
Rafael Espindola | 7296139 | 2012-11-02 20:57:36 +0000 | [diff] [blame] | 1120 | SchedTables.ProcSchedClasses[1 + (PI - SchedModels.procModelBegin())]; |
Andrew Trick | a72fca6 | 2012-09-17 22:18:50 +0000 | [diff] [blame] | 1121 | |
| 1122 | OS << "\n// {Name, NumMicroOps, BeginGroup, EndGroup," |
| 1123 | << " WriteProcResIdx,#, WriteLatencyIdx,#, ReadAdvanceIdx,#}\n"; |
| 1124 | OS << "static const llvm::MCSchedClassDesc " |
| 1125 | << PI->ModelName << "SchedClasses[] = {\n"; |
| 1126 | |
| 1127 | // The first class is always invalid. We no way to distinguish it except by |
| 1128 | // name and position. |
Andrew Trick | bf8a28d | 2013-03-16 18:58:55 +0000 | [diff] [blame] | 1129 | assert(SchedModels.getSchedClass(0).Name == "NoInstrModel" |
Andrew Trick | a72fca6 | 2012-09-17 22:18:50 +0000 | [diff] [blame] | 1130 | && "invalid class not first"); |
| 1131 | OS << " {DBGFIELD(\"InvalidSchedClass\") " |
| 1132 | << MCSchedClassDesc::InvalidNumMicroOps |
| 1133 | << ", 0, 0, 0, 0, 0, 0, 0, 0},\n"; |
| 1134 | |
| 1135 | for (unsigned SCIdx = 1, SCEnd = SCTab.size(); SCIdx != SCEnd; ++SCIdx) { |
| 1136 | MCSchedClassDesc &MCDesc = SCTab[SCIdx]; |
| 1137 | const CodeGenSchedClass &SchedClass = SchedModels.getSchedClass(SCIdx); |
| 1138 | OS << " {DBGFIELD(\"" << SchedClass.Name << "\") "; |
| 1139 | if (SchedClass.Name.size() < 18) |
| 1140 | OS.indent(18 - SchedClass.Name.size()); |
| 1141 | OS << MCDesc.NumMicroOps |
| 1142 | << ", " << MCDesc.BeginGroup << ", " << MCDesc.EndGroup |
| 1143 | << ", " << format("%2d", MCDesc.WriteProcResIdx) |
| 1144 | << ", " << MCDesc.NumWriteProcResEntries |
| 1145 | << ", " << format("%2d", MCDesc.WriteLatencyIdx) |
| 1146 | << ", " << MCDesc.NumWriteLatencyEntries |
| 1147 | << ", " << format("%2d", MCDesc.ReadAdvanceIdx) |
| 1148 | << ", " << MCDesc.NumReadAdvanceEntries << "}"; |
| 1149 | if (SCIdx + 1 < SCEnd) |
| 1150 | OS << ','; |
| 1151 | OS << " // #" << SCIdx << '\n'; |
| 1152 | } |
| 1153 | OS << "}; // " << PI->ModelName << "SchedClasses\n"; |
| 1154 | } |
| 1155 | } |
| 1156 | |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 1157 | void SubtargetEmitter::EmitProcessorModels(raw_ostream &OS) { |
| 1158 | // For each processor model. |
| 1159 | for (CodeGenSchedModels::ProcIter PI = SchedModels.procModelBegin(), |
| 1160 | PE = SchedModels.procModelEnd(); PI != PE; ++PI) { |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 1161 | // Emit processor resource table. |
| 1162 | if (PI->hasInstrSchedModel()) |
| 1163 | EmitProcessorResources(*PI, OS); |
| 1164 | else if(!PI->ProcResourceDefs.empty()) |
Joerg Sonnenberger | 635debe | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 1165 | PrintFatalError(PI->ModelDef->getLoc(), "SchedMachineModel defines " |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1166 | "ProcResources without defining WriteRes SchedWriteRes"); |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 1167 | |
Andrew Trick | 73d7736 | 2012-06-05 03:44:40 +0000 | [diff] [blame] | 1168 | // Begin processor itinerary properties |
| 1169 | OS << "\n"; |
Pete Cooper | 1175945 | 2014-09-02 17:43:54 +0000 | [diff] [blame] | 1170 | OS << "static const llvm::MCSchedModel " << PI->ModelName << " = {\n"; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 1171 | EmitProcessorProp(OS, PI->ModelDef, "IssueWidth", ','); |
Andrew Trick | de2109e | 2013-06-15 04:49:57 +0000 | [diff] [blame] | 1172 | EmitProcessorProp(OS, PI->ModelDef, "MicroOpBufferSize", ','); |
Hal Finkel | 6532c20 | 2014-05-08 09:14:44 +0000 | [diff] [blame] | 1173 | EmitProcessorProp(OS, PI->ModelDef, "LoopMicroOpBufferSize", ','); |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 1174 | EmitProcessorProp(OS, PI->ModelDef, "LoadLatency", ','); |
| 1175 | EmitProcessorProp(OS, PI->ModelDef, "HighLatency", ','); |
Andrew Trick | 352abc1 | 2012-08-08 02:44:16 +0000 | [diff] [blame] | 1176 | EmitProcessorProp(OS, PI->ModelDef, "MispredictPenalty", ','); |
Andrew Trick | b6854d8 | 2013-09-25 18:14:12 +0000 | [diff] [blame] | 1177 | |
| 1178 | OS << " " << (bool)(PI->ModelDef ? |
Sanjay Patel | a2f658d | 2014-07-15 22:39:58 +0000 | [diff] [blame] | 1179 | PI->ModelDef->getValueAsBit("PostRAScheduler") : 0) |
| 1180 | << ", // " << "PostRAScheduler\n"; |
| 1181 | |
| 1182 | OS << " " << (bool)(PI->ModelDef ? |
Andrew Trick | b6854d8 | 2013-09-25 18:14:12 +0000 | [diff] [blame] | 1183 | PI->ModelDef->getValueAsBit("CompleteModel") : 0) |
| 1184 | << ", // " << "CompleteModel\n"; |
| 1185 | |
Andrew Trick | ab722bd | 2012-09-18 03:18:56 +0000 | [diff] [blame] | 1186 | OS << " " << PI->Index << ", // Processor ID\n"; |
| 1187 | if (PI->hasInstrSchedModel()) |
| 1188 | OS << " " << PI->ModelName << "ProcResources" << ",\n" |
| 1189 | << " " << PI->ModelName << "SchedClasses" << ",\n" |
| 1190 | << " " << PI->ProcResourceDefs.size()+1 << ",\n" |
| 1191 | << " " << (SchedModels.schedClassEnd() |
| 1192 | - SchedModels.schedClassBegin()) << ",\n"; |
| 1193 | else |
Hans Wennborg | 083ca9b | 2015-10-06 23:24:35 +0000 | [diff] [blame] | 1194 | OS << " nullptr, nullptr, 0, 0," |
| 1195 | << " // No instruction-level machine model.\n"; |
Pete Cooper | 1175945 | 2014-09-02 17:43:54 +0000 | [diff] [blame] | 1196 | if (PI->hasItineraries()) |
| 1197 | OS << " " << PI->ItinsDef->getName() << "};\n"; |
Andrew Trick | 9c30267 | 2012-06-22 03:58:51 +0000 | [diff] [blame] | 1198 | else |
Pete Cooper | 1175945 | 2014-09-02 17:43:54 +0000 | [diff] [blame] | 1199 | OS << " nullptr}; // No Itinerary\n"; |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 1200 | } |
Jim Laskey | 3763a50 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | // |
| 1204 | // EmitProcessorLookup - generate cpu name to itinerary lookup table. |
| 1205 | // |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 1206 | void SubtargetEmitter::EmitProcessorLookup(raw_ostream &OS) { |
Jim Laskey | 3763a50 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 1207 | // Gather and sort processor information |
| 1208 | std::vector<Record*> ProcessorList = |
| 1209 | Records.getAllDerivedDefinitions("Processor"); |
Duraid Madina | 018da4f | 2005-12-30 14:56:37 +0000 | [diff] [blame] | 1210 | std::sort(ProcessorList.begin(), ProcessorList.end(), LessRecordFieldName()); |
Jim Laskey | 3763a50 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 1211 | |
| 1212 | // Begin processor table |
| 1213 | OS << "\n"; |
| 1214 | OS << "// Sorted (by key) array of itineraries for CPU subtype.\n" |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 1215 | << "extern const llvm::SubtargetInfoKV " |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 1216 | << Target << "ProcSchedKV[] = {\n"; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 1217 | |
Jim Laskey | 3763a50 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 1218 | // For each processor |
| 1219 | for (unsigned i = 0, N = ProcessorList.size(); i < N;) { |
| 1220 | // Next processor |
| 1221 | Record *Processor = ProcessorList[i]; |
| 1222 | |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 1223 | const std::string &Name = Processor->getValueAsString("Name"); |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 1224 | const std::string &ProcModelName = |
Andrew Trick | 7668649 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 1225 | SchedModels.getModelForProc(Processor).ModelName; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 1226 | |
Jim Laskey | 3763a50 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 1227 | // Emit as { "cpu", procinit }, |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 1228 | OS << " { \"" << Name << "\", (const void *)&" << ProcModelName << " }"; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 1229 | |
Jim Laskey | 3763a50 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 1230 | // Depending on ''if more in the list'' emit comma |
| 1231 | if (++i < N) OS << ","; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 1232 | |
Jim Laskey | 3763a50 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 1233 | OS << "\n"; |
| 1234 | } |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 1235 | |
Jim Laskey | 3763a50 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 1236 | // End processor table |
| 1237 | OS << "};\n"; |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | // |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 1241 | // EmitSchedModel - Emits all scheduling model tables, folding common patterns. |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 1242 | // |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 1243 | void SubtargetEmitter::EmitSchedModel(raw_ostream &OS) { |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 1244 | OS << "#ifdef DBGFIELD\n" |
| 1245 | << "#error \"<target>GenSubtargetInfo.inc requires a DBGFIELD macro\"\n" |
| 1246 | << "#endif\n" |
| 1247 | << "#ifndef NDEBUG\n" |
| 1248 | << "#define DBGFIELD(x) x,\n" |
| 1249 | << "#else\n" |
| 1250 | << "#define DBGFIELD(x)\n" |
| 1251 | << "#endif\n"; |
| 1252 | |
Andrew Trick | bf8a28d | 2013-03-16 18:58:55 +0000 | [diff] [blame] | 1253 | if (SchedModels.hasItineraries()) { |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 1254 | std::vector<std::vector<InstrItinerary> > ProcItinLists; |
Jim Laskey | 802748c | 2005-11-01 20:06:59 +0000 | [diff] [blame] | 1255 | // Emit the stage data |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 1256 | EmitStageAndOperandCycleData(OS, ProcItinLists); |
| 1257 | EmitItineraries(OS, ProcItinLists); |
Jim Laskey | 802748c | 2005-11-01 20:06:59 +0000 | [diff] [blame] | 1258 | } |
Andrew Trick | a72fca6 | 2012-09-17 22:18:50 +0000 | [diff] [blame] | 1259 | OS << "\n// ===============================================================\n" |
| 1260 | << "// Data tables for the new per-operand machine model.\n"; |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 1261 | |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1262 | SchedClassTables SchedTables; |
| 1263 | for (CodeGenSchedModels::ProcIter PI = SchedModels.procModelBegin(), |
| 1264 | PE = SchedModels.procModelEnd(); PI != PE; ++PI) { |
| 1265 | GenSchedClassTables(*PI, SchedTables); |
| 1266 | } |
Andrew Trick | a72fca6 | 2012-09-17 22:18:50 +0000 | [diff] [blame] | 1267 | EmitSchedClassTables(SchedTables, OS); |
| 1268 | |
| 1269 | // Emit the processor machine model |
| 1270 | EmitProcessorModels(OS); |
| 1271 | // Emit the processor lookup data |
| 1272 | EmitProcessorLookup(OS); |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1273 | |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 1274 | OS << "#undef DBGFIELD"; |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
Andrew Trick | c6c8815 | 2012-09-18 03:41:43 +0000 | [diff] [blame] | 1277 | void SubtargetEmitter::EmitSchedModelHelpers(std::string ClassName, |
| 1278 | raw_ostream &OS) { |
| 1279 | OS << "unsigned " << ClassName |
| 1280 | << "\n::resolveSchedClass(unsigned SchedClass, const MachineInstr *MI," |
| 1281 | << " const TargetSchedModel *SchedModel) const {\n"; |
| 1282 | |
| 1283 | std::vector<Record*> Prologs = Records.getAllDerivedDefinitions("PredicateProlog"); |
| 1284 | std::sort(Prologs.begin(), Prologs.end(), LessRecord()); |
| 1285 | for (std::vector<Record*>::const_iterator |
| 1286 | PI = Prologs.begin(), PE = Prologs.end(); PI != PE; ++PI) { |
| 1287 | OS << (*PI)->getValueAsString("Code") << '\n'; |
| 1288 | } |
| 1289 | IdxVec VariantClasses; |
| 1290 | for (CodeGenSchedModels::SchedClassIter SCI = SchedModels.schedClassBegin(), |
| 1291 | SCE = SchedModels.schedClassEnd(); SCI != SCE; ++SCI) { |
| 1292 | if (SCI->Transitions.empty()) |
| 1293 | continue; |
Andrew Trick | bf8a28d | 2013-03-16 18:58:55 +0000 | [diff] [blame] | 1294 | VariantClasses.push_back(SCI->Index); |
Andrew Trick | c6c8815 | 2012-09-18 03:41:43 +0000 | [diff] [blame] | 1295 | } |
| 1296 | if (!VariantClasses.empty()) { |
| 1297 | OS << " switch (SchedClass) {\n"; |
| 1298 | for (IdxIter VCI = VariantClasses.begin(), VCE = VariantClasses.end(); |
| 1299 | VCI != VCE; ++VCI) { |
| 1300 | const CodeGenSchedClass &SC = SchedModels.getSchedClass(*VCI); |
| 1301 | OS << " case " << *VCI << ": // " << SC.Name << '\n'; |
| 1302 | IdxVec ProcIndices; |
| 1303 | for (std::vector<CodeGenSchedTransition>::const_iterator |
| 1304 | TI = SC.Transitions.begin(), TE = SC.Transitions.end(); |
| 1305 | TI != TE; ++TI) { |
| 1306 | IdxVec PI; |
| 1307 | std::set_union(TI->ProcIndices.begin(), TI->ProcIndices.end(), |
| 1308 | ProcIndices.begin(), ProcIndices.end(), |
| 1309 | std::back_inserter(PI)); |
| 1310 | ProcIndices.swap(PI); |
| 1311 | } |
| 1312 | for (IdxIter PI = ProcIndices.begin(), PE = ProcIndices.end(); |
| 1313 | PI != PE; ++PI) { |
| 1314 | OS << " "; |
| 1315 | if (*PI != 0) |
| 1316 | OS << "if (SchedModel->getProcessorID() == " << *PI << ") "; |
| 1317 | OS << "{ // " << (SchedModels.procModelBegin() + *PI)->ModelName |
| 1318 | << '\n'; |
| 1319 | for (std::vector<CodeGenSchedTransition>::const_iterator |
| 1320 | TI = SC.Transitions.begin(), TE = SC.Transitions.end(); |
| 1321 | TI != TE; ++TI) { |
Andrew Trick | c6c8815 | 2012-09-18 03:41:43 +0000 | [diff] [blame] | 1322 | if (*PI != 0 && !std::count(TI->ProcIndices.begin(), |
| 1323 | TI->ProcIndices.end(), *PI)) { |
| 1324 | continue; |
| 1325 | } |
Arnold Schwaighofer | 218f6d8 | 2013-06-05 14:06:50 +0000 | [diff] [blame] | 1326 | OS << " if ("; |
Andrew Trick | c6c8815 | 2012-09-18 03:41:43 +0000 | [diff] [blame] | 1327 | for (RecIter RI = TI->PredTerm.begin(), RE = TI->PredTerm.end(); |
| 1328 | RI != RE; ++RI) { |
| 1329 | if (RI != TI->PredTerm.begin()) |
| 1330 | OS << "\n && "; |
| 1331 | OS << "(" << (*RI)->getValueAsString("Predicate") << ")"; |
| 1332 | } |
| 1333 | OS << ")\n" |
| 1334 | << " return " << TI->ToClassIdx << "; // " |
| 1335 | << SchedModels.getSchedClass(TI->ToClassIdx).Name << '\n'; |
| 1336 | } |
| 1337 | OS << " }\n"; |
| 1338 | if (*PI == 0) |
| 1339 | break; |
| 1340 | } |
Andrew Trick | bf8a28d | 2013-03-16 18:58:55 +0000 | [diff] [blame] | 1341 | if (SC.isInferred()) |
| 1342 | OS << " return " << SC.Index << ";\n"; |
Andrew Trick | c6c8815 | 2012-09-18 03:41:43 +0000 | [diff] [blame] | 1343 | OS << " break;\n"; |
| 1344 | } |
| 1345 | OS << " };\n"; |
| 1346 | } |
| 1347 | OS << " report_fatal_error(\"Expected a variant SchedClass\");\n" |
| 1348 | << "} // " << ClassName << "::resolveSchedClass\n"; |
| 1349 | } |
| 1350 | |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 1351 | // |
Jim Laskey | a2b5235 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 1352 | // ParseFeaturesFunction - Produces a subtarget specific function for parsing |
| 1353 | // the subtarget features string. |
| 1354 | // |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1355 | void SubtargetEmitter::ParseFeaturesFunction(raw_ostream &OS, |
| 1356 | unsigned NumFeatures, |
| 1357 | unsigned NumProcs) { |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 1358 | std::vector<Record*> Features = |
| 1359 | Records.getAllDerivedDefinitions("SubtargetFeature"); |
Duraid Madina | 018da4f | 2005-12-30 14:56:37 +0000 | [diff] [blame] | 1360 | std::sort(Features.begin(), Features.end(), LessRecord()); |
Jim Laskey | a2b5235 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 1361 | |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 1362 | OS << "// ParseSubtargetFeatures - Parses features string setting specified\n" |
| 1363 | << "// subtarget options.\n" |
Evan Cheng | fe6e405 | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 1364 | << "void llvm::"; |
Jim Laskey | a2b5235 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 1365 | OS << Target; |
Evan Cheng | 1a72add6 | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 1366 | OS << "Subtarget::ParseSubtargetFeatures(StringRef CPU, StringRef FS) {\n" |
David Greene | fb652a7 | 2010-01-05 17:47:41 +0000 | [diff] [blame] | 1367 | << " DEBUG(dbgs() << \"\\nFeatures:\" << FS);\n" |
Hal Finkel | 060f5d2 | 2012-06-12 04:21:36 +0000 | [diff] [blame] | 1368 | << " DEBUG(dbgs() << \"\\nCPU:\" << CPU << \"\\n\\n\");\n"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1369 | |
| 1370 | if (Features.empty()) { |
| 1371 | OS << "}\n"; |
| 1372 | return; |
| 1373 | } |
| 1374 | |
Andrew Trick | ba7b921 | 2012-09-18 05:33:15 +0000 | [diff] [blame] | 1375 | OS << " InitMCProcessorInfo(CPU, FS);\n" |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 1376 | << " const FeatureBitset& Bits = getFeatureBits();\n"; |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 1377 | |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 1378 | for (unsigned i = 0; i < Features.size(); i++) { |
| 1379 | // Next record |
| 1380 | Record *R = Features[i]; |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 1381 | const std::string &Instance = R->getName(); |
| 1382 | const std::string &Value = R->getValueAsString("Value"); |
| 1383 | const std::string &Attribute = R->getValueAsString("Attribute"); |
Evan Cheng | d98701c | 2006-01-27 08:09:42 +0000 | [diff] [blame] | 1384 | |
Dale Johannesen | 6ca3ccf | 2008-02-14 23:35:16 +0000 | [diff] [blame] | 1385 | if (Value=="true" || Value=="false") |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 1386 | OS << " if (Bits[" << Target << "::" |
| 1387 | << Instance << "]) " |
Dale Johannesen | 6ca3ccf | 2008-02-14 23:35:16 +0000 | [diff] [blame] | 1388 | << Attribute << " = " << Value << ";\n"; |
| 1389 | else |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 1390 | OS << " if (Bits[" << Target << "::" |
| 1391 | << Instance << "] && " |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1392 | << Attribute << " < " << Value << ") " |
| 1393 | << Attribute << " = " << Value << ";\n"; |
Jim Laskey | 802748c | 2005-11-01 20:06:59 +0000 | [diff] [blame] | 1394 | } |
Anton Korobeynikov | 08bf4c0 | 2009-05-23 19:50:50 +0000 | [diff] [blame] | 1395 | |
Evan Cheng | fe6e405 | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 1396 | OS << "}\n"; |
Jim Laskey | a2b5235 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 1397 | } |
| 1398 | |
Anton Korobeynikov | 08bf4c0 | 2009-05-23 19:50:50 +0000 | [diff] [blame] | 1399 | // |
Jim Laskey | cfda85a | 2005-10-21 19:00:04 +0000 | [diff] [blame] | 1400 | // SubtargetEmitter::run - Main subtarget enumeration emitter. |
| 1401 | // |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 1402 | void SubtargetEmitter::run(raw_ostream &OS) { |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 1403 | emitSourceFileHeader("Subtarget Enumeration Source Fragment", OS); |
Jim Laskey | cfda85a | 2005-10-21 19:00:04 +0000 | [diff] [blame] | 1404 | |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 1405 | OS << "\n#ifdef GET_SUBTARGETINFO_ENUM\n"; |
| 1406 | OS << "#undef GET_SUBTARGETINFO_ENUM\n"; |
| 1407 | |
| 1408 | OS << "namespace llvm {\n"; |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 1409 | Enumeration(OS, "SubtargetFeature"); |
Hans Wennborg | 083ca9b | 2015-10-06 23:24:35 +0000 | [diff] [blame] | 1410 | OS << "} // end llvm namespace\n"; |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 1411 | OS << "#endif // GET_SUBTARGETINFO_ENUM\n\n"; |
| 1412 | |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1413 | OS << "\n#ifdef GET_SUBTARGETINFO_MC_DESC\n"; |
| 1414 | OS << "#undef GET_SUBTARGETINFO_MC_DESC\n"; |
Anton Korobeynikov | 7d62e33 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 1415 | |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1416 | OS << "namespace llvm {\n"; |
Evan Cheng | bc153d4 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 1417 | #if 0 |
| 1418 | OS << "namespace {\n"; |
| 1419 | #endif |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1420 | unsigned NumFeatures = FeatureKeyValues(OS); |
Evan Cheng | bc153d4 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 1421 | OS << "\n"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1422 | unsigned NumProcs = CPUKeyValues(OS); |
Evan Cheng | bc153d4 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 1423 | OS << "\n"; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 1424 | EmitSchedModel(OS); |
Evan Cheng | bc153d4 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 1425 | OS << "\n"; |
| 1426 | #if 0 |
| 1427 | OS << "}\n"; |
| 1428 | #endif |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1429 | |
| 1430 | // MCInstrInfo initialization routine. |
Duncan P. N. Exon Smith | 754e21f | 2015-07-10 22:43:42 +0000 | [diff] [blame] | 1431 | OS << "static inline MCSubtargetInfo *create" << Target |
| 1432 | << "MCSubtargetInfoImpl(" |
Daniel Sanders | 50f1723 | 2015-09-15 16:17:27 +0000 | [diff] [blame] | 1433 | << "const Triple &TT, StringRef CPU, StringRef FS) {\n"; |
Duncan P. N. Exon Smith | 754e21f | 2015-07-10 22:43:42 +0000 | [diff] [blame] | 1434 | OS << " return new MCSubtargetInfo(TT, CPU, FS, "; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1435 | if (NumFeatures) |
| 1436 | OS << Target << "FeatureKV, "; |
| 1437 | else |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 1438 | OS << "None, "; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1439 | if (NumProcs) |
| 1440 | OS << Target << "SubTypeKV, "; |
| 1441 | else |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 1442 | OS << "None, "; |
Andrew Trick | a72fca6 | 2012-09-17 22:18:50 +0000 | [diff] [blame] | 1443 | OS << '\n'; OS.indent(22); |
Andrew Trick | ab722bd | 2012-09-18 03:18:56 +0000 | [diff] [blame] | 1444 | OS << Target << "ProcSchedKV, " |
| 1445 | << Target << "WriteProcResTable, " |
| 1446 | << Target << "WriteLatencyTable, " |
| 1447 | << Target << "ReadAdvanceTable, "; |
Andrew Trick | bf8a28d | 2013-03-16 18:58:55 +0000 | [diff] [blame] | 1448 | if (SchedModels.hasItineraries()) { |
Andrew Trick | ab722bd | 2012-09-18 03:18:56 +0000 | [diff] [blame] | 1449 | OS << '\n'; OS.indent(22); |
| 1450 | OS << Target << "Stages, " |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1451 | << Target << "OperandCycles, " |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 1452 | << Target << "ForwardingPaths"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1453 | } else |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 1454 | OS << "0, 0, 0"; |
| 1455 | OS << ");\n}\n\n"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1456 | |
Hans Wennborg | 083ca9b | 2015-10-06 23:24:35 +0000 | [diff] [blame] | 1457 | OS << "} // end llvm namespace\n"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1458 | |
| 1459 | OS << "#endif // GET_SUBTARGETINFO_MC_DESC\n\n"; |
| 1460 | |
| 1461 | OS << "\n#ifdef GET_SUBTARGETINFO_TARGET_DESC\n"; |
| 1462 | OS << "#undef GET_SUBTARGETINFO_TARGET_DESC\n"; |
| 1463 | |
| 1464 | OS << "#include \"llvm/Support/Debug.h\"\n"; |
Benjamin Kramer | b85d375 | 2015-03-23 18:45:56 +0000 | [diff] [blame] | 1465 | OS << "#include \"llvm/Support/raw_ostream.h\"\n"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1466 | ParseFeaturesFunction(OS, NumFeatures, NumProcs); |
| 1467 | |
| 1468 | OS << "#endif // GET_SUBTARGETINFO_TARGET_DESC\n\n"; |
| 1469 | |
Evan Cheng | 0d639a2 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 1470 | // Create a TargetSubtargetInfo subclass to hide the MC layer initialization. |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1471 | OS << "\n#ifdef GET_SUBTARGETINFO_HEADER\n"; |
| 1472 | OS << "#undef GET_SUBTARGETINFO_HEADER\n"; |
| 1473 | |
| 1474 | std::string ClassName = Target + "GenSubtargetInfo"; |
| 1475 | OS << "namespace llvm {\n"; |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 1476 | OS << "class DFAPacketizer;\n"; |
Evan Cheng | 0d639a2 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 1477 | OS << "struct " << ClassName << " : public TargetSubtargetInfo {\n" |
Daniel Sanders | 50f1723 | 2015-09-15 16:17:27 +0000 | [diff] [blame] | 1478 | << " explicit " << ClassName << "(const Triple &TT, StringRef CPU, " |
Evan Cheng | 1a72add6 | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 1479 | << "StringRef FS);\n" |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 1480 | << "public:\n" |
Daniel Sanders | a73f1fd | 2015-06-10 12:11:26 +0000 | [diff] [blame] | 1481 | << " unsigned resolveSchedClass(unsigned SchedClass, " |
| 1482 | << " const MachineInstr *DefMI," |
Craig Topper | 2d9361e | 2014-03-09 07:44:38 +0000 | [diff] [blame] | 1483 | << " const TargetSchedModel *SchedModel) const override;\n" |
Sebastian Pop | ac35a4d | 2011-12-06 17:34:16 +0000 | [diff] [blame] | 1484 | << " DFAPacketizer *createDFAPacketizer(const InstrItineraryData *IID)" |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 1485 | << " const;\n" |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1486 | << "};\n"; |
Hans Wennborg | 083ca9b | 2015-10-06 23:24:35 +0000 | [diff] [blame] | 1487 | OS << "} // end llvm namespace\n"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1488 | |
| 1489 | OS << "#endif // GET_SUBTARGETINFO_HEADER\n\n"; |
| 1490 | |
| 1491 | OS << "\n#ifdef GET_SUBTARGETINFO_CTOR\n"; |
| 1492 | OS << "#undef GET_SUBTARGETINFO_CTOR\n"; |
| 1493 | |
Andrew Trick | 1188e43 | 2012-09-18 03:32:57 +0000 | [diff] [blame] | 1494 | OS << "#include \"llvm/CodeGen/TargetSchedule.h\"\n"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1495 | OS << "namespace llvm {\n"; |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 1496 | OS << "extern const llvm::SubtargetFeatureKV " << Target << "FeatureKV[];\n"; |
| 1497 | OS << "extern const llvm::SubtargetFeatureKV " << Target << "SubTypeKV[];\n"; |
Andrew Trick | a72fca6 | 2012-09-17 22:18:50 +0000 | [diff] [blame] | 1498 | OS << "extern const llvm::SubtargetInfoKV " << Target << "ProcSchedKV[];\n"; |
| 1499 | OS << "extern const llvm::MCWriteProcResEntry " |
| 1500 | << Target << "WriteProcResTable[];\n"; |
| 1501 | OS << "extern const llvm::MCWriteLatencyEntry " |
| 1502 | << Target << "WriteLatencyTable[];\n"; |
| 1503 | OS << "extern const llvm::MCReadAdvanceEntry " |
| 1504 | << Target << "ReadAdvanceTable[];\n"; |
| 1505 | |
Andrew Trick | bf8a28d | 2013-03-16 18:58:55 +0000 | [diff] [blame] | 1506 | if (SchedModels.hasItineraries()) { |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 1507 | OS << "extern const llvm::InstrStage " << Target << "Stages[];\n"; |
| 1508 | OS << "extern const unsigned " << Target << "OperandCycles[];\n"; |
Andrew Trick | 030e2f8 | 2012-07-07 03:59:48 +0000 | [diff] [blame] | 1509 | OS << "extern const unsigned " << Target << "ForwardingPaths[];\n"; |
Evan Cheng | bc153d4 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 1510 | } |
| 1511 | |
Daniel Sanders | 50f1723 | 2015-09-15 16:17:27 +0000 | [diff] [blame] | 1512 | OS << ClassName << "::" << ClassName << "(const Triple &TT, StringRef CPU, " |
| 1513 | << "StringRef FS)\n" |
Duncan P. N. Exon Smith | 754e21f | 2015-07-10 22:43:42 +0000 | [diff] [blame] | 1514 | << " : TargetSubtargetInfo(TT, CPU, FS, "; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1515 | if (NumFeatures) |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 1516 | OS << "makeArrayRef(" << Target << "FeatureKV, " << NumFeatures << "), "; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1517 | else |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 1518 | OS << "None, "; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1519 | if (NumProcs) |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 1520 | OS << "makeArrayRef(" << Target << "SubTypeKV, " << NumProcs << "), "; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1521 | else |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 1522 | OS << "None, "; |
Duncan P. N. Exon Smith | 754e21f | 2015-07-10 22:43:42 +0000 | [diff] [blame] | 1523 | OS << '\n'; OS.indent(24); |
Andrew Trick | ab722bd | 2012-09-18 03:18:56 +0000 | [diff] [blame] | 1524 | OS << Target << "ProcSchedKV, " |
| 1525 | << Target << "WriteProcResTable, " |
| 1526 | << Target << "WriteLatencyTable, " |
| 1527 | << Target << "ReadAdvanceTable, "; |
Duncan P. N. Exon Smith | 754e21f | 2015-07-10 22:43:42 +0000 | [diff] [blame] | 1528 | OS << '\n'; OS.indent(24); |
Andrew Trick | bf8a28d | 2013-03-16 18:58:55 +0000 | [diff] [blame] | 1529 | if (SchedModels.hasItineraries()) { |
Andrew Trick | ab722bd | 2012-09-18 03:18:56 +0000 | [diff] [blame] | 1530 | OS << Target << "Stages, " |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1531 | << Target << "OperandCycles, " |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 1532 | << Target << "ForwardingPaths"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1533 | } else |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 1534 | OS << "0, 0, 0"; |
Duncan P. N. Exon Smith | 754e21f | 2015-07-10 22:43:42 +0000 | [diff] [blame] | 1535 | OS << ") {}\n\n"; |
Andrew Trick | a72fca6 | 2012-09-17 22:18:50 +0000 | [diff] [blame] | 1536 | |
Andrew Trick | c6c8815 | 2012-09-18 03:41:43 +0000 | [diff] [blame] | 1537 | EmitSchedModelHelpers(ClassName, OS); |
| 1538 | |
Hans Wennborg | 083ca9b | 2015-10-06 23:24:35 +0000 | [diff] [blame] | 1539 | OS << "} // end llvm namespace\n"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1540 | |
| 1541 | OS << "#endif // GET_SUBTARGETINFO_CTOR\n\n"; |
Jim Laskey | cfda85a | 2005-10-21 19:00:04 +0000 | [diff] [blame] | 1542 | } |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 1543 | |
| 1544 | namespace llvm { |
| 1545 | |
| 1546 | void EmitSubtarget(RecordKeeper &RK, raw_ostream &OS) { |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 1547 | CodeGenTarget CGTarget(RK); |
| 1548 | SubtargetEmitter(RK, CGTarget).run(OS); |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 1549 | } |
| 1550 | |
Hans Wennborg | 083ca9b | 2015-10-06 23:24:35 +0000 | [diff] [blame] | 1551 | } // end llvm namespace |