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