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