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