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" |
Jim Laskey | 4bb9cbb | 2005-10-21 19:00:04 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/StringExtras.h" |
Jakob Stoklund Olesen | 6f36fa9 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 16 | #include "llvm/MC/MCInstrItineraries.h" |
Jim Laskey | 4bb9cbb | 2005-10-21 19:00:04 +0000 | [diff] [blame] | 17 | #include "llvm/Support/Debug.h" |
Jakob Stoklund Olesen | 6f36fa9 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 18 | #include "llvm/TableGen/Record.h" |
| 19 | #include "llvm/TableGen/TableGenBackend.h" |
Jeff Cohen | 9489c04 | 2005-10-28 01:43:09 +0000 | [diff] [blame] | 20 | #include <algorithm> |
Jakob Stoklund Olesen | 6f36fa9 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 21 | #include <map> |
| 22 | #include <string> |
| 23 | #include <vector> |
Jim Laskey | 4bb9cbb | 2005-10-21 19:00:04 +0000 | [diff] [blame] | 24 | using namespace llvm; |
| 25 | |
Jakob Stoklund Olesen | 6f36fa9 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 26 | namespace { |
| 27 | class SubtargetEmitter { |
| 28 | |
| 29 | RecordKeeper &Records; |
| 30 | std::string Target; |
| 31 | bool HasItineraries; |
| 32 | |
| 33 | void Enumeration(raw_ostream &OS, const char *ClassName, bool isBits); |
| 34 | unsigned FeatureKeyValues(raw_ostream &OS); |
| 35 | unsigned CPUKeyValues(raw_ostream &OS); |
| 36 | unsigned CollectAllItinClasses(raw_ostream &OS, |
| 37 | std::map<std::string,unsigned> &ItinClassesMap, |
| 38 | std::vector<Record*> &ItinClassList); |
| 39 | void FormItineraryStageString(const std::string &Names, |
| 40 | Record *ItinData, std::string &ItinString, |
| 41 | unsigned &NStages); |
| 42 | void FormItineraryOperandCycleString(Record *ItinData, std::string &ItinString, |
| 43 | unsigned &NOperandCycles); |
| 44 | void FormItineraryBypassString(const std::string &Names, |
| 45 | Record *ItinData, |
| 46 | std::string &ItinString, unsigned NOperandCycles); |
| 47 | void EmitStageAndOperandCycleData(raw_ostream &OS, unsigned NItinClasses, |
| 48 | std::map<std::string, unsigned> &ItinClassesMap, |
| 49 | std::vector<Record*> &ItinClassList, |
| 50 | std::vector<std::vector<InstrItinerary> > &ProcList); |
| 51 | void EmitItineraryProp(raw_ostream &OS, const Record *R, const char *Name, |
| 52 | char Separator); |
| 53 | void EmitProcessorData(raw_ostream &OS, |
| 54 | std::vector<Record*> &ItinClassList, |
| 55 | std::vector<std::vector<InstrItinerary> > &ProcList); |
| 56 | void EmitProcessorLookup(raw_ostream &OS); |
| 57 | void EmitData(raw_ostream &OS); |
| 58 | void ParseFeaturesFunction(raw_ostream &OS, unsigned NumFeatures, |
| 59 | unsigned NumProcs); |
| 60 | |
| 61 | public: |
| 62 | SubtargetEmitter(RecordKeeper &R) : Records(R), HasItineraries(false) {} |
| 63 | |
| 64 | void run(raw_ostream &o); |
| 65 | |
| 66 | }; |
| 67 | } // End anonymous namespace |
| 68 | |
Jim Laskey | 7dc0204 | 2005-10-22 07:59:56 +0000 | [diff] [blame] | 69 | // |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 70 | // Enumeration - Emit the specified class as an enumeration. |
Jim Laskey | b3b1d5f | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 71 | // |
Daniel Dunbar | 1a55180 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 72 | void SubtargetEmitter::Enumeration(raw_ostream &OS, |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 73 | const char *ClassName, |
| 74 | bool isBits) { |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 75 | // Get all records of class and sort |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 76 | std::vector<Record*> DefList = Records.getAllDerivedDefinitions(ClassName); |
Duraid Madina | 42d24c7 | 2005-12-30 14:56:37 +0000 | [diff] [blame] | 77 | std::sort(DefList.begin(), DefList.end(), LessRecord()); |
Jim Laskey | b3b1d5f | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 78 | |
Evan Cheng | b6a6388 | 2011-04-15 19:35:46 +0000 | [diff] [blame] | 79 | unsigned N = DefList.size(); |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 80 | if (N == 0) |
| 81 | return; |
Evan Cheng | b6a6388 | 2011-04-15 19:35:46 +0000 | [diff] [blame] | 82 | if (N > 64) { |
| 83 | errs() << "Too many (> 64) subtarget features!\n"; |
| 84 | exit(1); |
| 85 | } |
| 86 | |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 87 | OS << "namespace " << Target << " {\n"; |
| 88 | |
Jakob Stoklund Olesen | ac1ed44 | 2012-01-03 23:04:28 +0000 | [diff] [blame] | 89 | // For bit flag enumerations with more than 32 items, emit constants. |
| 90 | // Emit an enum for everything else. |
| 91 | if (isBits && N > 32) { |
| 92 | // For each record |
| 93 | for (unsigned i = 0; i < N; i++) { |
| 94 | // Next record |
| 95 | Record *Def = DefList[i]; |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 96 | |
Jakob Stoklund Olesen | ac1ed44 | 2012-01-03 23:04:28 +0000 | [diff] [blame] | 97 | // Get and emit name and expression (1 << i) |
| 98 | OS << " const uint64_t " << Def->getName() << " = 1ULL << " << i << ";\n"; |
| 99 | } |
| 100 | } else { |
| 101 | // Open enumeration |
| 102 | OS << "enum {\n"; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 103 | |
Jakob Stoklund Olesen | ac1ed44 | 2012-01-03 23:04:28 +0000 | [diff] [blame] | 104 | // For each record |
| 105 | for (unsigned i = 0; i < N;) { |
| 106 | // Next record |
| 107 | Record *Def = DefList[i]; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 108 | |
Jakob Stoklund Olesen | ac1ed44 | 2012-01-03 23:04:28 +0000 | [diff] [blame] | 109 | // Get and emit name |
| 110 | OS << " " << Def->getName(); |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 111 | |
Jakob Stoklund Olesen | ac1ed44 | 2012-01-03 23:04:28 +0000 | [diff] [blame] | 112 | // If bit flags then emit expression (1 << i) |
| 113 | if (isBits) OS << " = " << " 1ULL << " << i; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 114 | |
Jakob Stoklund Olesen | ac1ed44 | 2012-01-03 23:04:28 +0000 | [diff] [blame] | 115 | // Depending on 'if more in the list' emit comma |
| 116 | if (++i < N) OS << ","; |
| 117 | |
| 118 | OS << "\n"; |
| 119 | } |
| 120 | |
| 121 | // Close enumeration |
| 122 | OS << "};\n"; |
Jim Laskey | b3b1d5f | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 123 | } |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 124 | |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 125 | OS << "}\n"; |
Jim Laskey | b3b1d5f | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | // |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 129 | // FeatureKeyValues - Emit data of all the subtarget features. Used by the |
| 130 | // command line. |
Jim Laskey | b3b1d5f | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 131 | // |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 132 | unsigned SubtargetEmitter::FeatureKeyValues(raw_ostream &OS) { |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 133 | // Gather and sort all the features |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 134 | std::vector<Record*> FeatureList = |
| 135 | Records.getAllDerivedDefinitions("SubtargetFeature"); |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 136 | |
| 137 | if (FeatureList.empty()) |
| 138 | return 0; |
| 139 | |
Jim Grosbach | 7c9a772 | 2008-09-11 17:05:32 +0000 | [diff] [blame] | 140 | std::sort(FeatureList.begin(), FeatureList.end(), LessRecordFieldName()); |
Jim Laskey | b3b1d5f | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 141 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 142 | // Begin feature table |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 143 | OS << "// Sorted (by key) array of values for CPU features.\n" |
Benjamin Kramer | 1a2f988 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 144 | << "extern const llvm::SubtargetFeatureKV " << Target |
| 145 | << "FeatureKV[] = {\n"; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 146 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 147 | // For each feature |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 148 | unsigned NumFeatures = 0; |
Jim Laskey | dbe4006 | 2006-12-12 20:55:58 +0000 | [diff] [blame] | 149 | for (unsigned i = 0, N = FeatureList.size(); i < N; ++i) { |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 150 | // Next feature |
| 151 | Record *Feature = FeatureList[i]; |
| 152 | |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 153 | const std::string &Name = Feature->getName(); |
| 154 | const std::string &CommandLineName = Feature->getValueAsString("Name"); |
| 155 | const std::string &Desc = Feature->getValueAsString("Desc"); |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 156 | |
Jim Laskey | dbe4006 | 2006-12-12 20:55:58 +0000 | [diff] [blame] | 157 | if (CommandLineName.empty()) continue; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 158 | |
Jim Grosbach | da4231f | 2009-03-26 16:17:51 +0000 | [diff] [blame] | 159 | // Emit as { "feature", "description", featureEnum, i1 | i2 | ... | in } |
Jim Laskey | b3b1d5f | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 160 | OS << " { " |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 161 | << "\"" << CommandLineName << "\", " |
Jim Laskey | b3b1d5f | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 162 | << "\"" << Desc << "\", " |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 163 | << Target << "::" << Name << ", "; |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 164 | |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 165 | const std::vector<Record*> &ImpliesList = |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 166 | Feature->getValueAsListOfDefs("Implies"); |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 167 | |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 168 | if (ImpliesList.empty()) { |
Evan Cheng | b6a6388 | 2011-04-15 19:35:46 +0000 | [diff] [blame] | 169 | OS << "0ULL"; |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 170 | } else { |
| 171 | for (unsigned j = 0, M = ImpliesList.size(); j < M;) { |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 172 | OS << Target << "::" << ImpliesList[j]->getName(); |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 173 | if (++j < M) OS << " | "; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | OS << " }"; |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 178 | ++NumFeatures; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 179 | |
Jim Laskey | 10b1dd9 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 180 | // Depending on 'if more in the list' emit comma |
Jim Laskey | dbe4006 | 2006-12-12 20:55:58 +0000 | [diff] [blame] | 181 | if ((i + 1) < N) OS << ","; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 182 | |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 183 | OS << "\n"; |
Jim Laskey | b3b1d5f | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 184 | } |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 185 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 186 | // End feature table |
Jim Laskey | b3b1d5f | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 187 | OS << "};\n"; |
| 188 | |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 189 | return NumFeatures; |
Jim Laskey | b3b1d5f | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | // |
| 193 | // CPUKeyValues - Emit data of all the subtarget processors. Used by command |
| 194 | // line. |
| 195 | // |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 196 | unsigned SubtargetEmitter::CPUKeyValues(raw_ostream &OS) { |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 197 | // Gather and sort processor information |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 198 | std::vector<Record*> ProcessorList = |
| 199 | Records.getAllDerivedDefinitions("Processor"); |
Duraid Madina | 42d24c7 | 2005-12-30 14:56:37 +0000 | [diff] [blame] | 200 | std::sort(ProcessorList.begin(), ProcessorList.end(), LessRecordFieldName()); |
Jim Laskey | b3b1d5f | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 201 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 202 | // Begin processor table |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 203 | OS << "// Sorted (by key) array of values for CPU subtype.\n" |
Benjamin Kramer | 1a2f988 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 204 | << "extern const llvm::SubtargetFeatureKV " << Target |
| 205 | << "SubTypeKV[] = {\n"; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 206 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 207 | // For each processor |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 208 | for (unsigned i = 0, N = ProcessorList.size(); i < N;) { |
| 209 | // Next processor |
| 210 | Record *Processor = ProcessorList[i]; |
| 211 | |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 212 | const std::string &Name = Processor->getValueAsString("Name"); |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 213 | const std::vector<Record*> &FeatureList = |
Chris Lattner | b0e103d | 2005-10-28 22:49:02 +0000 | [diff] [blame] | 214 | Processor->getValueAsListOfDefs("Features"); |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 215 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 216 | // Emit as { "cpu", "description", f1 | f2 | ... fn }, |
Jim Laskey | b3b1d5f | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 217 | OS << " { " |
| 218 | << "\"" << Name << "\", " |
| 219 | << "\"Select the " << Name << " processor\", "; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 220 | |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 221 | if (FeatureList.empty()) { |
Evan Cheng | b6a6388 | 2011-04-15 19:35:46 +0000 | [diff] [blame] | 222 | OS << "0ULL"; |
Jim Laskey | b3b1d5f | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 223 | } else { |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 224 | for (unsigned j = 0, M = FeatureList.size(); j < M;) { |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 225 | OS << Target << "::" << FeatureList[j]->getName(); |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 226 | if (++j < M) OS << " | "; |
Jim Laskey | b3b1d5f | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 227 | } |
| 228 | } |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 229 | |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 230 | // The "0" is for the "implies" section of this data structure. |
Evan Cheng | b6a6388 | 2011-04-15 19:35:46 +0000 | [diff] [blame] | 231 | OS << ", 0ULL }"; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 232 | |
Jim Laskey | 10b1dd9 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 233 | // Depending on 'if more in the list' emit comma |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 234 | if (++i < N) OS << ","; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 235 | |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 236 | OS << "\n"; |
Jim Laskey | b3b1d5f | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 237 | } |
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 | // End processor table |
Jim Laskey | b3b1d5f | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 240 | OS << "};\n"; |
| 241 | |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 242 | return ProcessorList.size(); |
Jim Laskey | b3b1d5f | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 243 | } |
Jim Laskey | 7dc0204 | 2005-10-22 07:59:56 +0000 | [diff] [blame] | 244 | |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 245 | // |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 246 | // CollectAllItinClasses - Gathers and enumerates all the itinerary classes. |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 247 | // Returns itinerary class count. |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 248 | // |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 249 | unsigned SubtargetEmitter:: |
| 250 | CollectAllItinClasses(raw_ostream &OS, |
| 251 | std::map<std::string, unsigned> &ItinClassesMap, |
| 252 | std::vector<Record*> &ItinClassList) { |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 253 | // For each itinerary class |
| 254 | unsigned N = ItinClassList.size(); |
| 255 | for (unsigned i = 0; i < N; i++) { |
| 256 | // Next itinerary class |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 257 | const Record *ItinClass = ItinClassList[i]; |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 258 | // Get name of itinerary class |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 259 | // Assign itinerary class a unique number |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 260 | ItinClassesMap[ItinClass->getName()] = i; |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 261 | } |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 262 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 263 | // Return itinerary class count |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 264 | return N; |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | // |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 268 | // FormItineraryStageString - Compose a string containing the stage |
| 269 | // data initialization for the specified itinerary. N is the number |
| 270 | // of stages. |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 271 | // |
Anton Korobeynikov | 928eb49 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 272 | void SubtargetEmitter::FormItineraryStageString(const std::string &Name, |
| 273 | Record *ItinData, |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 274 | std::string &ItinString, |
| 275 | unsigned &NStages) { |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 276 | // Get states list |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 277 | const std::vector<Record*> &StageList = |
| 278 | ItinData->getValueAsListOfDefs("Stages"); |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 279 | |
| 280 | // For each stage |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 281 | unsigned N = NStages = StageList.size(); |
Christopher Lamb | 8dadf6b | 2007-04-22 09:04:24 +0000 | [diff] [blame] | 282 | for (unsigned i = 0; i < N;) { |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 283 | // Next stage |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 284 | const Record *Stage = StageList[i]; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 285 | |
Anton Korobeynikov | 96085a3 | 2010-04-07 18:19:32 +0000 | [diff] [blame] | 286 | // Form string as ,{ cycles, u1 | u2 | ... | un, timeinc, kind } |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 287 | int Cycles = Stage->getValueAsInt("Cycles"); |
Jim Laskey | 7f39c14 | 2005-11-03 22:47:41 +0000 | [diff] [blame] | 288 | ItinString += " { " + itostr(Cycles) + ", "; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 289 | |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 290 | // Get unit list |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 291 | const std::vector<Record*> &UnitList = Stage->getValueAsListOfDefs("Units"); |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 292 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 293 | // For each unit |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 294 | for (unsigned j = 0, M = UnitList.size(); j < M;) { |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 295 | // Add name and bitwise or |
Anton Korobeynikov | 928eb49 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 296 | ItinString += Name + "FU::" + UnitList[j]->getName(); |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 297 | if (++j < M) ItinString += " | "; |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 298 | } |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 299 | |
David Goodwin | 1a8f36e | 2009-08-12 18:31:53 +0000 | [diff] [blame] | 300 | int TimeInc = Stage->getValueAsInt("TimeInc"); |
| 301 | ItinString += ", " + itostr(TimeInc); |
| 302 | |
Anton Korobeynikov | 96085a3 | 2010-04-07 18:19:32 +0000 | [diff] [blame] | 303 | int Kind = Stage->getValueAsInt("Kind"); |
| 304 | ItinString += ", (llvm::InstrStage::ReservationKinds)" + itostr(Kind); |
| 305 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 306 | // Close off stage |
| 307 | ItinString += " }"; |
Christopher Lamb | 8dadf6b | 2007-04-22 09:04:24 +0000 | [diff] [blame] | 308 | if (++i < N) ItinString += ", "; |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 309 | } |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | // |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 313 | // FormItineraryOperandCycleString - Compose a string containing the |
| 314 | // operand cycle initialization for the specified itinerary. N is the |
| 315 | // number of operands that has cycles specified. |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 316 | // |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 317 | void SubtargetEmitter::FormItineraryOperandCycleString(Record *ItinData, |
| 318 | std::string &ItinString, unsigned &NOperandCycles) { |
| 319 | // Get operand cycle list |
| 320 | const std::vector<int64_t> &OperandCycleList = |
| 321 | ItinData->getValueAsListOfInts("OperandCycles"); |
| 322 | |
| 323 | // For each operand cycle |
| 324 | unsigned N = NOperandCycles = OperandCycleList.size(); |
| 325 | for (unsigned i = 0; i < N;) { |
| 326 | // Next operand cycle |
| 327 | const int OCycle = OperandCycleList[i]; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 328 | |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 329 | ItinString += " " + itostr(OCycle); |
| 330 | if (++i < N) ItinString += ", "; |
| 331 | } |
| 332 | } |
| 333 | |
Evan Cheng | 63d66ee | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 334 | void SubtargetEmitter::FormItineraryBypassString(const std::string &Name, |
| 335 | Record *ItinData, |
| 336 | std::string &ItinString, |
| 337 | unsigned NOperandCycles) { |
| 338 | const std::vector<Record*> &BypassList = |
| 339 | ItinData->getValueAsListOfDefs("Bypasses"); |
| 340 | unsigned N = BypassList.size(); |
Evan Cheng | 3881cb7 | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 341 | unsigned i = 0; |
| 342 | for (; i < N;) { |
Evan Cheng | 63d66ee | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 343 | ItinString += Name + "Bypass::" + BypassList[i]->getName(); |
Evan Cheng | 3881cb7 | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 344 | if (++i < NOperandCycles) ItinString += ", "; |
Evan Cheng | 63d66ee | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 345 | } |
Evan Cheng | 3881cb7 | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 346 | for (; i < NOperandCycles;) { |
Evan Cheng | 63d66ee | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 347 | ItinString += " 0"; |
Evan Cheng | 3881cb7 | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 348 | if (++i < NOperandCycles) ItinString += ", "; |
Evan Cheng | 63d66ee | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 352 | // |
| 353 | // EmitStageAndOperandCycleData - Generate unique itinerary stages and |
| 354 | // operand cycle tables. Record itineraries for processors. |
| 355 | // |
| 356 | void SubtargetEmitter::EmitStageAndOperandCycleData(raw_ostream &OS, |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 357 | unsigned NItinClasses, |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 358 | std::map<std::string, unsigned> &ItinClassesMap, |
| 359 | std::vector<Record*> &ItinClassList, |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 360 | std::vector<std::vector<InstrItinerary> > &ProcList) { |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 361 | // Gather processor iteraries |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 362 | std::vector<Record*> ProcItinList = |
| 363 | Records.getAllDerivedDefinitions("ProcessorItineraries"); |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 364 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 365 | // If just no itinerary then don't bother |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 366 | if (ProcItinList.size() < 2) return; |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 367 | |
Anton Korobeynikov | 928eb49 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 368 | // Emit functional units for all the itineraries. |
| 369 | for (unsigned i = 0, N = ProcItinList.size(); i < N; ++i) { |
| 370 | // Next record |
| 371 | Record *Proc = ProcItinList[i]; |
| 372 | |
| 373 | std::vector<Record*> FUs = Proc->getValueAsListOfDefs("FU"); |
| 374 | if (FUs.empty()) |
| 375 | continue; |
| 376 | |
| 377 | const std::string &Name = Proc->getName(); |
| 378 | OS << "\n// Functional units for itineraries \"" << Name << "\"\n" |
| 379 | << "namespace " << Name << "FU {\n"; |
| 380 | |
| 381 | for (unsigned j = 0, FUN = FUs.size(); j < FUN; ++j) |
Hal Finkel | b460a33 | 2012-06-22 20:27:13 +0000 | [diff] [blame] | 382 | OS << " const unsigned " << FUs[j]->getName() |
| 383 | << " = 1 << " << j << ";\n"; |
Anton Korobeynikov | 928eb49 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 384 | |
| 385 | OS << "}\n"; |
Evan Cheng | 63d66ee | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 386 | |
| 387 | std::vector<Record*> BPs = Proc->getValueAsListOfDefs("BP"); |
Evan Cheng | 3881cb7 | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 388 | if (BPs.size()) { |
| 389 | OS << "\n// Pipeline forwarding pathes for itineraries \"" << Name |
| 390 | << "\"\n" << "namespace " << Name << "Bypass {\n"; |
Evan Cheng | 63d66ee | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 391 | |
Benjamin Kramer | 1a2f988 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 392 | OS << " const unsigned NoBypass = 0;\n"; |
Evan Cheng | 3881cb7 | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 393 | for (unsigned j = 0, BPN = BPs.size(); j < BPN; ++j) |
Benjamin Kramer | 1a2f988 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 394 | OS << " const unsigned " << BPs[j]->getName() |
Evan Cheng | 3881cb7 | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 395 | << " = 1 << " << j << ";\n"; |
Evan Cheng | 63d66ee | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 396 | |
Evan Cheng | 3881cb7 | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 397 | OS << "}\n"; |
| 398 | } |
Anton Korobeynikov | 928eb49 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 399 | } |
| 400 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 401 | // Begin stages table |
Benjamin Kramer | 1a2f988 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 402 | std::string StageTable = "\nextern const llvm::InstrStage " + Target + |
| 403 | "Stages[] = {\n"; |
Anton Korobeynikov | 96085a3 | 2010-04-07 18:19:32 +0000 | [diff] [blame] | 404 | StageTable += " { 0, 0, 0, llvm::InstrStage::Required }, // No itinerary\n"; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 405 | |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 406 | // Begin operand cycle table |
Benjamin Kramer | 1a2f988 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 407 | std::string OperandCycleTable = "extern const unsigned " + Target + |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 408 | "OperandCycles[] = {\n"; |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 409 | OperandCycleTable += " 0, // No itinerary\n"; |
Evan Cheng | 63d66ee | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 410 | |
| 411 | // Begin pipeline bypass table |
Benjamin Kramer | 1a2f988 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 412 | std::string BypassTable = "extern const unsigned " + Target + |
Andrew Trick | a11a628 | 2012-07-07 03:59:48 +0000 | [diff] [blame^] | 413 | "ForwardingPaths[] = {\n"; |
Evan Cheng | 63d66ee | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 414 | BypassTable += " 0, // No itinerary\n"; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 415 | |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 416 | unsigned StageCount = 1, OperandCycleCount = 1; |
Evan Cheng | 3881cb7 | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 417 | std::map<std::string, unsigned> ItinStageMap, ItinOperandMap; |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 418 | for (unsigned i = 0, N = ProcItinList.size(); i < N; i++) { |
| 419 | // Next record |
| 420 | Record *Proc = ProcItinList[i]; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 421 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 422 | // Get processor itinerary name |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 423 | const std::string &Name = Proc->getName(); |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 424 | |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 425 | // Get itinerary data list |
Chris Lattner | b0e103d | 2005-10-28 22:49:02 +0000 | [diff] [blame] | 426 | std::vector<Record*> ItinDataList = Proc->getValueAsListOfDefs("IID"); |
Andrew Trick | d85934b | 2012-06-22 03:58:51 +0000 | [diff] [blame] | 427 | std::vector<InstrItinerary> ItinList; |
| 428 | |
| 429 | // Add an empty itinerary. |
| 430 | if (ItinDataList.empty()) { |
| 431 | ProcList.push_back(ItinList); |
| 432 | continue; |
| 433 | } |
| 434 | |
| 435 | // Expand processor itinerary to cover all itinerary classes |
| 436 | ItinList.resize(NItinClasses); |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 437 | |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 438 | // For each itinerary data |
| 439 | for (unsigned j = 0, M = ItinDataList.size(); j < M; j++) { |
| 440 | // Next itinerary data |
| 441 | Record *ItinData = ItinDataList[j]; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 442 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 443 | // Get string and stage count |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 444 | std::string ItinStageString; |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 445 | unsigned NStages; |
Anton Korobeynikov | 928eb49 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 446 | FormItineraryStageString(Name, ItinData, ItinStageString, NStages); |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 447 | |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 448 | // Get string and operand cycle count |
| 449 | std::string ItinOperandCycleString; |
| 450 | unsigned NOperandCycles; |
| 451 | FormItineraryOperandCycleString(ItinData, ItinOperandCycleString, |
| 452 | NOperandCycles); |
| 453 | |
Evan Cheng | 63d66ee | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 454 | std::string ItinBypassString; |
| 455 | FormItineraryBypassString(Name, ItinData, ItinBypassString, |
| 456 | NOperandCycles); |
| 457 | |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 458 | // Check to see if stage already exists and create if it doesn't |
| 459 | unsigned FindStage = 0; |
| 460 | if (NStages > 0) { |
| 461 | FindStage = ItinStageMap[ItinStageString]; |
| 462 | if (FindStage == 0) { |
Andrew Trick | 2348232 | 2011-04-01 02:22:47 +0000 | [diff] [blame] | 463 | // Emit as { cycles, u1 | u2 | ... | un, timeinc }, // indices |
| 464 | StageTable += ItinStageString + ", // " + itostr(StageCount); |
| 465 | if (NStages > 1) |
| 466 | StageTable += "-" + itostr(StageCount + NStages - 1); |
| 467 | StageTable += "\n"; |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 468 | // Record Itin class number. |
| 469 | ItinStageMap[ItinStageString] = FindStage = StageCount; |
| 470 | StageCount += NStages; |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 471 | } |
| 472 | } |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 473 | |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 474 | // Check to see if operand cycle already exists and create if it doesn't |
| 475 | unsigned FindOperandCycle = 0; |
| 476 | if (NOperandCycles > 0) { |
Evan Cheng | 3881cb7 | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 477 | std::string ItinOperandString = ItinOperandCycleString+ItinBypassString; |
| 478 | FindOperandCycle = ItinOperandMap[ItinOperandString]; |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 479 | if (FindOperandCycle == 0) { |
| 480 | // Emit as cycle, // index |
Andrew Trick | 2348232 | 2011-04-01 02:22:47 +0000 | [diff] [blame] | 481 | OperandCycleTable += ItinOperandCycleString + ", // "; |
| 482 | std::string OperandIdxComment = itostr(OperandCycleCount); |
| 483 | if (NOperandCycles > 1) |
| 484 | OperandIdxComment += "-" |
| 485 | + itostr(OperandCycleCount + NOperandCycles - 1); |
| 486 | OperandCycleTable += OperandIdxComment + "\n"; |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 487 | // Record Itin class number. |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 488 | ItinOperandMap[ItinOperandCycleString] = |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 489 | FindOperandCycle = OperandCycleCount; |
Evan Cheng | 63d66ee | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 490 | // Emit as bypass, // index |
Andrew Trick | 2348232 | 2011-04-01 02:22:47 +0000 | [diff] [blame] | 491 | BypassTable += ItinBypassString + ", // " + OperandIdxComment + "\n"; |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 492 | OperandCycleCount += NOperandCycles; |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 493 | } |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 494 | } |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 495 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 496 | // Locate where to inject into processor itinerary table |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 497 | const std::string &Name = ItinData->getValueAsDef("TheClass")->getName(); |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 498 | unsigned Find = ItinClassesMap[Name]; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 499 | |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 500 | // Set up itinerary as location and location + stage count |
Chandler Carruth | 506bb19 | 2012-07-02 18:28:34 +0000 | [diff] [blame] | 501 | int NumUOps = ItinData->getValueAsInt("NumMicroOps"); |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 502 | InstrItinerary Intinerary = { NumUOps, FindStage, FindStage + NStages, |
| 503 | FindOperandCycle, |
| 504 | FindOperandCycle + NOperandCycles}; |
| 505 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 506 | // Inject - empty slots will be 0, 0 |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 507 | ItinList[Find] = Intinerary; |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 508 | } |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 509 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 510 | // Add process itinerary to list |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 511 | ProcList.push_back(ItinList); |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 512 | } |
Evan Cheng | 63d66ee | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 513 | |
Jim Laskey | 7f39c14 | 2005-11-03 22:47:41 +0000 | [diff] [blame] | 514 | // Closing stage |
Anton Korobeynikov | 96085a3 | 2010-04-07 18:19:32 +0000 | [diff] [blame] | 515 | StageTable += " { 0, 0, 0, llvm::InstrStage::Required } // End itinerary\n"; |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 516 | StageTable += "};\n"; |
| 517 | |
| 518 | // Closing operand cycles |
| 519 | OperandCycleTable += " 0 // End itinerary\n"; |
| 520 | OperandCycleTable += "};\n"; |
| 521 | |
Evan Cheng | 63d66ee | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 522 | BypassTable += " 0 // End itinerary\n"; |
| 523 | BypassTable += "};\n"; |
| 524 | |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 525 | // Emit tables. |
| 526 | OS << StageTable; |
| 527 | OS << OperandCycleTable; |
Evan Cheng | 63d66ee | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 528 | OS << BypassTable; |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 529 | } |
| 530 | |
Andrew Trick | fc99299 | 2012-06-05 03:44:40 +0000 | [diff] [blame] | 531 | void SubtargetEmitter::EmitItineraryProp(raw_ostream &OS, const Record *R, |
| 532 | const char *Name, char Separator) { |
| 533 | OS << " "; |
| 534 | int V = R->getValueAsInt(Name); |
| 535 | if (V >= 0) |
| 536 | OS << V << Separator << " // " << Name; |
| 537 | else |
Andrew Trick | 0076ad7 | 2012-06-08 18:25:47 +0000 | [diff] [blame] | 538 | OS << "InstrItineraryProps::Default" << Name << Separator; |
Andrew Trick | fc99299 | 2012-06-05 03:44:40 +0000 | [diff] [blame] | 539 | OS << '\n'; |
| 540 | } |
| 541 | |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 542 | // |
Jim Laskey | 10b1dd9 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 543 | // EmitProcessorData - Generate data for processor itineraries. |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 544 | // |
Andrew Trick | 2348232 | 2011-04-01 02:22:47 +0000 | [diff] [blame] | 545 | void SubtargetEmitter:: |
| 546 | EmitProcessorData(raw_ostream &OS, |
| 547 | std::vector<Record*> &ItinClassList, |
| 548 | std::vector<std::vector<InstrItinerary> > &ProcList) { |
Andrew Trick | fc99299 | 2012-06-05 03:44:40 +0000 | [diff] [blame] | 549 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 550 | // Get an iterator for processor itinerary stages |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 551 | std::vector<std::vector<InstrItinerary> >::iterator |
| 552 | ProcListIter = ProcList.begin(); |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 553 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 554 | // For each processor itinerary |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 555 | std::vector<Record*> Itins = |
| 556 | Records.getAllDerivedDefinitions("ProcessorItineraries"); |
| 557 | for (unsigned i = 0, N = Itins.size(); i < N; i++) { |
| 558 | // Next record |
| 559 | Record *Itin = Itins[i]; |
| 560 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 561 | // Get processor itinerary name |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 562 | const std::string &Name = Itin->getName(); |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 563 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 564 | // Skip default |
Andrew Trick | fc99299 | 2012-06-05 03:44:40 +0000 | [diff] [blame] | 565 | // Begin processor itinerary properties |
| 566 | OS << "\n"; |
| 567 | OS << "static const llvm::InstrItineraryProps " << Name << "Props(\n"; |
| 568 | EmitItineraryProp(OS, Itin, "IssueWidth", ','); |
| 569 | EmitItineraryProp(OS, Itin, "MinLatency", ','); |
| 570 | EmitItineraryProp(OS, Itin, "LoadLatency", ','); |
| 571 | EmitItineraryProp(OS, Itin, "HighLatency", ' '); |
| 572 | OS << ");\n"; |
| 573 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 574 | // For each itinerary class |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 575 | std::vector<InstrItinerary> &ItinList = *ProcListIter++; |
Andrew Trick | d85934b | 2012-06-22 03:58:51 +0000 | [diff] [blame] | 576 | if (!ItinList.empty()) { |
| 577 | assert(ItinList.size() == ItinClassList.size() && "bad itinerary"); |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 578 | |
Andrew Trick | d85934b | 2012-06-22 03:58:51 +0000 | [diff] [blame] | 579 | // Begin processor itinerary table |
| 580 | OS << "\n"; |
| 581 | OS << "static const llvm::InstrItinerary " << Name << "Entries" |
| 582 | << "[] = {\n"; |
| 583 | |
| 584 | for (unsigned j = 0, M = ItinList.size(); j < M; ++j) { |
| 585 | InstrItinerary &Intinerary = ItinList[j]; |
| 586 | |
| 587 | // Emit in the form of |
| 588 | // { firstStage, lastStage, firstCycle, lastCycle } // index |
| 589 | if (Intinerary.FirstStage == 0) { |
| 590 | OS << " { 1, 0, 0, 0, 0 }"; |
| 591 | } else { |
| 592 | OS << " { " << |
| 593 | Intinerary.NumMicroOps << ", " << |
| 594 | Intinerary.FirstStage << ", " << |
| 595 | Intinerary.LastStage << ", " << |
| 596 | Intinerary.FirstOperandCycle << ", " << |
| 597 | Intinerary.LastOperandCycle << " }"; |
| 598 | } |
| 599 | OS << ", // " << j << " " << ItinClassList[j]->getName() << "\n"; |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 600 | } |
Andrew Trick | d85934b | 2012-06-22 03:58:51 +0000 | [diff] [blame] | 601 | // End processor itinerary table |
| 602 | OS << " { 1, ~0U, ~0U, ~0U, ~0U } // end marker\n"; |
| 603 | OS << "};\n"; |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 604 | } |
Andrew Trick | fc99299 | 2012-06-05 03:44:40 +0000 | [diff] [blame] | 605 | OS << '\n'; |
| 606 | OS << "static const llvm::InstrItinerarySubtargetValue " |
| 607 | << Name << " = {\n"; |
| 608 | OS << " &" << Name << "Props,\n"; |
Andrew Trick | d85934b | 2012-06-22 03:58:51 +0000 | [diff] [blame] | 609 | if (ItinList.empty()) |
| 610 | OS << " 0\n"; |
| 611 | else |
| 612 | OS << " " << Name << "Entries\n"; |
Andrew Trick | fc99299 | 2012-06-05 03:44:40 +0000 | [diff] [blame] | 613 | OS << "};\n"; |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 614 | } |
Jim Laskey | 10b1dd9 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | // |
| 618 | // EmitProcessorLookup - generate cpu name to itinerary lookup table. |
| 619 | // |
Daniel Dunbar | 1a55180 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 620 | void SubtargetEmitter::EmitProcessorLookup(raw_ostream &OS) { |
Jim Laskey | 10b1dd9 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 621 | // Gather and sort processor information |
| 622 | std::vector<Record*> ProcessorList = |
| 623 | Records.getAllDerivedDefinitions("Processor"); |
Duraid Madina | 42d24c7 | 2005-12-30 14:56:37 +0000 | [diff] [blame] | 624 | std::sort(ProcessorList.begin(), ProcessorList.end(), LessRecordFieldName()); |
Jim Laskey | 10b1dd9 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 625 | |
| 626 | // Begin processor table |
| 627 | OS << "\n"; |
| 628 | OS << "// Sorted (by key) array of itineraries for CPU subtype.\n" |
Benjamin Kramer | 1a2f988 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 629 | << "extern const llvm::SubtargetInfoKV " |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 630 | << Target << "ProcItinKV[] = {\n"; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 631 | |
Jim Laskey | 10b1dd9 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 632 | // For each processor |
| 633 | for (unsigned i = 0, N = ProcessorList.size(); i < N;) { |
| 634 | // Next processor |
| 635 | Record *Processor = ProcessorList[i]; |
| 636 | |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 637 | const std::string &Name = Processor->getValueAsString("Name"); |
| 638 | const std::string &ProcItin = |
| 639 | Processor->getValueAsDef("ProcItin")->getName(); |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 640 | |
Jim Laskey | 10b1dd9 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 641 | // Emit as { "cpu", procinit }, |
| 642 | OS << " { " |
| 643 | << "\"" << Name << "\", " |
| 644 | << "(void *)&" << ProcItin; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 645 | |
Jim Laskey | 10b1dd9 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 646 | OS << " }"; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 647 | |
Jim Laskey | 10b1dd9 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 648 | // Depending on ''if more in the list'' emit comma |
| 649 | if (++i < N) OS << ","; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 650 | |
Jim Laskey | 10b1dd9 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 651 | OS << "\n"; |
| 652 | } |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 653 | |
Jim Laskey | 10b1dd9 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 654 | // End processor table |
| 655 | OS << "};\n"; |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | // |
| 659 | // EmitData - Emits all stages and itineries, folding common patterns. |
| 660 | // |
Daniel Dunbar | 1a55180 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 661 | void SubtargetEmitter::EmitData(raw_ostream &OS) { |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 662 | std::map<std::string, unsigned> ItinClassesMap; |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 663 | // Gather and sort all itinerary classes |
| 664 | std::vector<Record*> ItinClassList = |
| 665 | Records.getAllDerivedDefinitions("InstrItinClass"); |
| 666 | std::sort(ItinClassList.begin(), ItinClassList.end(), LessRecord()); |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 667 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 668 | // Enumerate all the itinerary classes |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 669 | unsigned NItinClasses = CollectAllItinClasses(OS, ItinClassesMap, |
| 670 | ItinClassList); |
Jim Laskey | 6cee630 | 2005-11-01 20:06:59 +0000 | [diff] [blame] | 671 | // Make sure the rest is worth the effort |
Chris Lattner | 387e4bd | 2006-01-27 01:41:55 +0000 | [diff] [blame] | 672 | HasItineraries = NItinClasses != 1; // Ignore NoItinerary. |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 673 | |
Jim Laskey | 6cee630 | 2005-11-01 20:06:59 +0000 | [diff] [blame] | 674 | if (HasItineraries) { |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 675 | std::vector<std::vector<InstrItinerary> > ProcList; |
Jim Laskey | 6cee630 | 2005-11-01 20:06:59 +0000 | [diff] [blame] | 676 | // Emit the stage data |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 677 | EmitStageAndOperandCycleData(OS, NItinClasses, ItinClassesMap, |
| 678 | ItinClassList, ProcList); |
Jim Laskey | 6cee630 | 2005-11-01 20:06:59 +0000 | [diff] [blame] | 679 | // Emit the processor itinerary data |
Andrew Trick | 2348232 | 2011-04-01 02:22:47 +0000 | [diff] [blame] | 680 | EmitProcessorData(OS, ItinClassList, ProcList); |
Jim Laskey | 6cee630 | 2005-11-01 20:06:59 +0000 | [diff] [blame] | 681 | // Emit the processor lookup data |
| 682 | EmitProcessorLookup(OS); |
| 683 | } |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | // |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 687 | // ParseFeaturesFunction - Produces a subtarget specific function for parsing |
| 688 | // the subtarget features string. |
| 689 | // |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 690 | void SubtargetEmitter::ParseFeaturesFunction(raw_ostream &OS, |
| 691 | unsigned NumFeatures, |
| 692 | unsigned NumProcs) { |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 693 | std::vector<Record*> Features = |
| 694 | Records.getAllDerivedDefinitions("SubtargetFeature"); |
Duraid Madina | 42d24c7 | 2005-12-30 14:56:37 +0000 | [diff] [blame] | 695 | std::sort(Features.begin(), Features.end(), LessRecord()); |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 696 | |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 697 | OS << "// ParseSubtargetFeatures - Parses features string setting specified\n" |
| 698 | << "// subtarget options.\n" |
Evan Cheng | 276365d | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 699 | << "void llvm::"; |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 700 | OS << Target; |
Evan Cheng | 0ddff1b | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 701 | OS << "Subtarget::ParseSubtargetFeatures(StringRef CPU, StringRef FS) {\n" |
David Greene | f0fd3af | 2010-01-05 17:47:41 +0000 | [diff] [blame] | 702 | << " DEBUG(dbgs() << \"\\nFeatures:\" << FS);\n" |
Hal Finkel | 3f696e5 | 2012-06-12 04:21:36 +0000 | [diff] [blame] | 703 | << " DEBUG(dbgs() << \"\\nCPU:\" << CPU << \"\\n\\n\");\n"; |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 704 | |
| 705 | if (Features.empty()) { |
| 706 | OS << "}\n"; |
| 707 | return; |
| 708 | } |
| 709 | |
Evan Cheng | 0ddff1b | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 710 | OS << " uint64_t Bits = ReInitMCSubtargetInfo(CPU, FS);\n"; |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 711 | |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 712 | for (unsigned i = 0; i < Features.size(); i++) { |
| 713 | // Next record |
| 714 | Record *R = Features[i]; |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 715 | const std::string &Instance = R->getName(); |
| 716 | const std::string &Value = R->getValueAsString("Value"); |
| 717 | const std::string &Attribute = R->getValueAsString("Attribute"); |
Evan Cheng | 19c9550 | 2006-01-27 08:09:42 +0000 | [diff] [blame] | 718 | |
Dale Johannesen | db01c8b | 2008-02-14 23:35:16 +0000 | [diff] [blame] | 719 | if (Value=="true" || Value=="false") |
Evan Cheng | 0ddff1b | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 720 | OS << " if ((Bits & " << Target << "::" |
| 721 | << Instance << ") != 0) " |
Dale Johannesen | db01c8b | 2008-02-14 23:35:16 +0000 | [diff] [blame] | 722 | << Attribute << " = " << Value << ";\n"; |
| 723 | else |
Evan Cheng | 0ddff1b | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 724 | OS << " if ((Bits & " << Target << "::" |
| 725 | << Instance << ") != 0 && " |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 726 | << Attribute << " < " << Value << ") " |
| 727 | << Attribute << " = " << Value << ";\n"; |
Jim Laskey | 6cee630 | 2005-11-01 20:06:59 +0000 | [diff] [blame] | 728 | } |
Anton Korobeynikov | 41a0243 | 2009-05-23 19:50:50 +0000 | [diff] [blame] | 729 | |
Evan Cheng | 276365d | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 730 | OS << "}\n"; |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 731 | } |
| 732 | |
Anton Korobeynikov | 41a0243 | 2009-05-23 19:50:50 +0000 | [diff] [blame] | 733 | // |
Jim Laskey | 4bb9cbb | 2005-10-21 19:00:04 +0000 | [diff] [blame] | 734 | // SubtargetEmitter::run - Main subtarget enumeration emitter. |
| 735 | // |
Daniel Dunbar | 1a55180 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 736 | void SubtargetEmitter::run(raw_ostream &OS) { |
Chris Lattner | 67db883 | 2010-12-13 00:23:57 +0000 | [diff] [blame] | 737 | Target = CodeGenTarget(Records).getName(); |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 738 | |
Jakob Stoklund Olesen | 6f36fa9 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 739 | emitSourceFileHeader("Subtarget Enumeration Source Fragment", OS); |
Jim Laskey | 4bb9cbb | 2005-10-21 19:00:04 +0000 | [diff] [blame] | 740 | |
Evan Cheng | ebdeeab | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 741 | OS << "\n#ifdef GET_SUBTARGETINFO_ENUM\n"; |
| 742 | OS << "#undef GET_SUBTARGETINFO_ENUM\n"; |
| 743 | |
| 744 | OS << "namespace llvm {\n"; |
| 745 | Enumeration(OS, "SubtargetFeature", true); |
| 746 | OS << "} // End llvm namespace \n"; |
| 747 | OS << "#endif // GET_SUBTARGETINFO_ENUM\n\n"; |
| 748 | |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 749 | OS << "\n#ifdef GET_SUBTARGETINFO_MC_DESC\n"; |
| 750 | OS << "#undef GET_SUBTARGETINFO_MC_DESC\n"; |
Anton Korobeynikov | 928eb49 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 751 | |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 752 | OS << "namespace llvm {\n"; |
Evan Cheng | c60f9b7 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 753 | #if 0 |
| 754 | OS << "namespace {\n"; |
| 755 | #endif |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 756 | unsigned NumFeatures = FeatureKeyValues(OS); |
Evan Cheng | c60f9b7 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 757 | OS << "\n"; |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 758 | unsigned NumProcs = CPUKeyValues(OS); |
Evan Cheng | c60f9b7 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 759 | OS << "\n"; |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 760 | EmitData(OS); |
Evan Cheng | c60f9b7 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 761 | OS << "\n"; |
| 762 | #if 0 |
| 763 | OS << "}\n"; |
| 764 | #endif |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 765 | |
| 766 | // MCInstrInfo initialization routine. |
| 767 | OS << "static inline void Init" << Target |
Evan Cheng | 59ee62d | 2011-07-11 03:57:24 +0000 | [diff] [blame] | 768 | << "MCSubtargetInfo(MCSubtargetInfo *II, " |
| 769 | << "StringRef TT, StringRef CPU, StringRef FS) {\n"; |
| 770 | OS << " II->InitMCSubtargetInfo(TT, CPU, FS, "; |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 771 | if (NumFeatures) |
| 772 | OS << Target << "FeatureKV, "; |
| 773 | else |
| 774 | OS << "0, "; |
| 775 | if (NumProcs) |
| 776 | OS << Target << "SubTypeKV, "; |
| 777 | else |
| 778 | OS << "0, "; |
| 779 | if (HasItineraries) { |
| 780 | OS << Target << "ProcItinKV, " |
| 781 | << Target << "Stages, " |
| 782 | << Target << "OperandCycles, " |
Andrew Trick | a11a628 | 2012-07-07 03:59:48 +0000 | [diff] [blame^] | 783 | << Target << "ForwardingPaths, "; |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 784 | } else |
| 785 | OS << "0, 0, 0, 0, "; |
| 786 | OS << NumFeatures << ", " << NumProcs << ");\n}\n\n"; |
| 787 | |
| 788 | OS << "} // End llvm namespace \n"; |
| 789 | |
| 790 | OS << "#endif // GET_SUBTARGETINFO_MC_DESC\n\n"; |
| 791 | |
| 792 | OS << "\n#ifdef GET_SUBTARGETINFO_TARGET_DESC\n"; |
| 793 | OS << "#undef GET_SUBTARGETINFO_TARGET_DESC\n"; |
| 794 | |
| 795 | OS << "#include \"llvm/Support/Debug.h\"\n"; |
| 796 | OS << "#include \"llvm/Support/raw_ostream.h\"\n"; |
| 797 | ParseFeaturesFunction(OS, NumFeatures, NumProcs); |
| 798 | |
| 799 | OS << "#endif // GET_SUBTARGETINFO_TARGET_DESC\n\n"; |
| 800 | |
Evan Cheng | 5b1b4489 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 801 | // Create a TargetSubtargetInfo subclass to hide the MC layer initialization. |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 802 | OS << "\n#ifdef GET_SUBTARGETINFO_HEADER\n"; |
| 803 | OS << "#undef GET_SUBTARGETINFO_HEADER\n"; |
| 804 | |
| 805 | std::string ClassName = Target + "GenSubtargetInfo"; |
| 806 | OS << "namespace llvm {\n"; |
Anshuman Dasgupta | dc81e5d | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 807 | OS << "class DFAPacketizer;\n"; |
Evan Cheng | 5b1b4489 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 808 | OS << "struct " << ClassName << " : public TargetSubtargetInfo {\n" |
Evan Cheng | 0ddff1b | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 809 | << " explicit " << ClassName << "(StringRef TT, StringRef CPU, " |
| 810 | << "StringRef FS);\n" |
Anshuman Dasgupta | dc81e5d | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 811 | << "public:\n" |
Sebastian Pop | 464f3a3 | 2011-12-06 17:34:16 +0000 | [diff] [blame] | 812 | << " DFAPacketizer *createDFAPacketizer(const InstrItineraryData *IID)" |
Anshuman Dasgupta | dc81e5d | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 813 | << " const;\n" |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 814 | << "};\n"; |
| 815 | OS << "} // End llvm namespace \n"; |
| 816 | |
| 817 | OS << "#endif // GET_SUBTARGETINFO_HEADER\n\n"; |
| 818 | |
| 819 | OS << "\n#ifdef GET_SUBTARGETINFO_CTOR\n"; |
| 820 | OS << "#undef GET_SUBTARGETINFO_CTOR\n"; |
| 821 | |
| 822 | OS << "namespace llvm {\n"; |
Benjamin Kramer | 1a2f988 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 823 | OS << "extern const llvm::SubtargetFeatureKV " << Target << "FeatureKV[];\n"; |
| 824 | OS << "extern const llvm::SubtargetFeatureKV " << Target << "SubTypeKV[];\n"; |
Evan Cheng | c60f9b7 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 825 | if (HasItineraries) { |
Benjamin Kramer | 1a2f988 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 826 | OS << "extern const llvm::SubtargetInfoKV " << Target << "ProcItinKV[];\n"; |
| 827 | OS << "extern const llvm::InstrStage " << Target << "Stages[];\n"; |
| 828 | OS << "extern const unsigned " << Target << "OperandCycles[];\n"; |
Andrew Trick | a11a628 | 2012-07-07 03:59:48 +0000 | [diff] [blame^] | 829 | OS << "extern const unsigned " << Target << "ForwardingPaths[];\n"; |
Evan Cheng | c60f9b7 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 830 | } |
| 831 | |
Evan Cheng | 0ddff1b | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 832 | OS << ClassName << "::" << ClassName << "(StringRef TT, StringRef CPU, " |
| 833 | << "StringRef FS)\n" |
Evan Cheng | 5b1b4489 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 834 | << " : TargetSubtargetInfo() {\n" |
Evan Cheng | 59ee62d | 2011-07-11 03:57:24 +0000 | [diff] [blame] | 835 | << " InitMCSubtargetInfo(TT, CPU, FS, "; |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 836 | if (NumFeatures) |
| 837 | OS << Target << "FeatureKV, "; |
| 838 | else |
| 839 | OS << "0, "; |
| 840 | if (NumProcs) |
| 841 | OS << Target << "SubTypeKV, "; |
| 842 | else |
| 843 | OS << "0, "; |
| 844 | if (HasItineraries) { |
| 845 | OS << Target << "ProcItinKV, " |
| 846 | << Target << "Stages, " |
| 847 | << Target << "OperandCycles, " |
Andrew Trick | a11a628 | 2012-07-07 03:59:48 +0000 | [diff] [blame^] | 848 | << Target << "ForwardingPaths, "; |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 849 | } else |
| 850 | OS << "0, 0, 0, 0, "; |
| 851 | OS << NumFeatures << ", " << NumProcs << ");\n}\n\n"; |
| 852 | OS << "} // End llvm namespace \n"; |
| 853 | |
| 854 | OS << "#endif // GET_SUBTARGETINFO_CTOR\n\n"; |
Jim Laskey | 4bb9cbb | 2005-10-21 19:00:04 +0000 | [diff] [blame] | 855 | } |
Jakob Stoklund Olesen | 6f36fa9 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 856 | |
| 857 | namespace llvm { |
| 858 | |
| 859 | void EmitSubtarget(RecordKeeper &RK, raw_ostream &OS) { |
| 860 | SubtargetEmitter(RK).run(OS); |
| 861 | } |
| 862 | |
| 863 | } // End llvm namespace |