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