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 | e877c4f | 2012-06-18 21:08:18 +0000 | [diff] [blame^] | 382 | OS << " const uint64_t " << FUs[j]->getName() |
| 383 | << " = 1ULL << " << 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 + |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 413 | "ForwardingPathes[] = {\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 | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 425 | // Skip default |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 426 | if (Name == "NoItineraries") continue; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 427 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 428 | // Create and expand processor itinerary to cover all itinerary classes |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 429 | std::vector<InstrItinerary> ItinList; |
| 430 | ItinList.resize(NItinClasses); |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 431 | |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 432 | // Get itinerary data list |
Chris Lattner | b0e103d | 2005-10-28 22:49:02 +0000 | [diff] [blame] | 433 | std::vector<Record*> ItinDataList = Proc->getValueAsListOfDefs("IID"); |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 434 | |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 435 | // For each itinerary data |
| 436 | for (unsigned j = 0, M = ItinDataList.size(); j < M; j++) { |
| 437 | // Next itinerary data |
| 438 | Record *ItinData = ItinDataList[j]; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 439 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 440 | // Get string and stage count |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 441 | std::string ItinStageString; |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 442 | unsigned NStages; |
Anton Korobeynikov | 928eb49 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 443 | FormItineraryStageString(Name, ItinData, ItinStageString, NStages); |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 444 | |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 445 | // Get string and operand cycle count |
| 446 | std::string ItinOperandCycleString; |
| 447 | unsigned NOperandCycles; |
| 448 | FormItineraryOperandCycleString(ItinData, ItinOperandCycleString, |
| 449 | NOperandCycles); |
| 450 | |
Evan Cheng | 63d66ee | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 451 | std::string ItinBypassString; |
| 452 | FormItineraryBypassString(Name, ItinData, ItinBypassString, |
| 453 | NOperandCycles); |
| 454 | |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 455 | // Check to see if stage already exists and create if it doesn't |
| 456 | unsigned FindStage = 0; |
| 457 | if (NStages > 0) { |
| 458 | FindStage = ItinStageMap[ItinStageString]; |
| 459 | if (FindStage == 0) { |
Andrew Trick | 2348232 | 2011-04-01 02:22:47 +0000 | [diff] [blame] | 460 | // Emit as { cycles, u1 | u2 | ... | un, timeinc }, // indices |
| 461 | StageTable += ItinStageString + ", // " + itostr(StageCount); |
| 462 | if (NStages > 1) |
| 463 | StageTable += "-" + itostr(StageCount + NStages - 1); |
| 464 | StageTable += "\n"; |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 465 | // Record Itin class number. |
| 466 | ItinStageMap[ItinStageString] = FindStage = StageCount; |
| 467 | StageCount += NStages; |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 468 | } |
| 469 | } |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 470 | |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 471 | // Check to see if operand cycle already exists and create if it doesn't |
| 472 | unsigned FindOperandCycle = 0; |
| 473 | if (NOperandCycles > 0) { |
Evan Cheng | 3881cb7 | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 474 | std::string ItinOperandString = ItinOperandCycleString+ItinBypassString; |
| 475 | FindOperandCycle = ItinOperandMap[ItinOperandString]; |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 476 | if (FindOperandCycle == 0) { |
| 477 | // Emit as cycle, // index |
Andrew Trick | 2348232 | 2011-04-01 02:22:47 +0000 | [diff] [blame] | 478 | OperandCycleTable += ItinOperandCycleString + ", // "; |
| 479 | std::string OperandIdxComment = itostr(OperandCycleCount); |
| 480 | if (NOperandCycles > 1) |
| 481 | OperandIdxComment += "-" |
| 482 | + itostr(OperandCycleCount + NOperandCycles - 1); |
| 483 | OperandCycleTable += OperandIdxComment + "\n"; |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 484 | // Record Itin class number. |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 485 | ItinOperandMap[ItinOperandCycleString] = |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 486 | FindOperandCycle = OperandCycleCount; |
Evan Cheng | 63d66ee | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 487 | // Emit as bypass, // index |
Andrew Trick | 2348232 | 2011-04-01 02:22:47 +0000 | [diff] [blame] | 488 | BypassTable += ItinBypassString + ", // " + OperandIdxComment + "\n"; |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 489 | OperandCycleCount += NOperandCycles; |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 490 | } |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 491 | } |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 492 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 493 | // Locate where to inject into processor itinerary table |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 494 | const std::string &Name = ItinData->getValueAsDef("TheClass")->getName(); |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 495 | unsigned Find = ItinClassesMap[Name]; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 496 | |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 497 | // Set up itinerary as location and location + stage count |
| 498 | unsigned NumUOps = ItinClassList[Find]->getValueAsInt("NumMicroOps"); |
| 499 | InstrItinerary Intinerary = { NumUOps, FindStage, FindStage + NStages, |
| 500 | FindOperandCycle, |
| 501 | FindOperandCycle + NOperandCycles}; |
| 502 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 503 | // Inject - empty slots will be 0, 0 |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 504 | ItinList[Find] = Intinerary; |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 505 | } |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 506 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 507 | // Add process itinerary to list |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 508 | ProcList.push_back(ItinList); |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 509 | } |
Evan Cheng | 63d66ee | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 510 | |
Jim Laskey | 7f39c14 | 2005-11-03 22:47:41 +0000 | [diff] [blame] | 511 | // Closing stage |
Anton Korobeynikov | 96085a3 | 2010-04-07 18:19:32 +0000 | [diff] [blame] | 512 | StageTable += " { 0, 0, 0, llvm::InstrStage::Required } // End itinerary\n"; |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 513 | StageTable += "};\n"; |
| 514 | |
| 515 | // Closing operand cycles |
| 516 | OperandCycleTable += " 0 // End itinerary\n"; |
| 517 | OperandCycleTable += "};\n"; |
| 518 | |
Evan Cheng | 63d66ee | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 519 | BypassTable += " 0 // End itinerary\n"; |
| 520 | BypassTable += "};\n"; |
| 521 | |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 522 | // Emit tables. |
| 523 | OS << StageTable; |
| 524 | OS << OperandCycleTable; |
Evan Cheng | 63d66ee | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 525 | OS << BypassTable; |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 526 | } |
| 527 | |
Andrew Trick | fc99299 | 2012-06-05 03:44:40 +0000 | [diff] [blame] | 528 | void SubtargetEmitter::EmitItineraryProp(raw_ostream &OS, const Record *R, |
| 529 | const char *Name, char Separator) { |
| 530 | OS << " "; |
| 531 | int V = R->getValueAsInt(Name); |
| 532 | if (V >= 0) |
| 533 | OS << V << Separator << " // " << Name; |
| 534 | else |
Andrew Trick | 0076ad7 | 2012-06-08 18:25:47 +0000 | [diff] [blame] | 535 | OS << "InstrItineraryProps::Default" << Name << Separator; |
Andrew Trick | fc99299 | 2012-06-05 03:44:40 +0000 | [diff] [blame] | 536 | OS << '\n'; |
| 537 | } |
| 538 | |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 539 | // |
Jim Laskey | 10b1dd9 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 540 | // EmitProcessorData - Generate data for processor itineraries. |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 541 | // |
Andrew Trick | 2348232 | 2011-04-01 02:22:47 +0000 | [diff] [blame] | 542 | void SubtargetEmitter:: |
| 543 | EmitProcessorData(raw_ostream &OS, |
| 544 | std::vector<Record*> &ItinClassList, |
| 545 | std::vector<std::vector<InstrItinerary> > &ProcList) { |
Andrew Trick | fc99299 | 2012-06-05 03:44:40 +0000 | [diff] [blame] | 546 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 547 | // Get an iterator for processor itinerary stages |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 548 | std::vector<std::vector<InstrItinerary> >::iterator |
| 549 | ProcListIter = ProcList.begin(); |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 550 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 551 | // For each processor itinerary |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 552 | std::vector<Record*> Itins = |
| 553 | Records.getAllDerivedDefinitions("ProcessorItineraries"); |
| 554 | for (unsigned i = 0, N = Itins.size(); i < N; i++) { |
| 555 | // Next record |
| 556 | Record *Itin = Itins[i]; |
| 557 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 558 | // Get processor itinerary name |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 559 | const std::string &Name = Itin->getName(); |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 560 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 561 | // Skip default |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 562 | if (Name == "NoItineraries") continue; |
| 563 | |
Andrew Trick | fc99299 | 2012-06-05 03:44:40 +0000 | [diff] [blame] | 564 | // Begin processor itinerary properties |
| 565 | OS << "\n"; |
| 566 | OS << "static const llvm::InstrItineraryProps " << Name << "Props(\n"; |
| 567 | EmitItineraryProp(OS, Itin, "IssueWidth", ','); |
| 568 | EmitItineraryProp(OS, Itin, "MinLatency", ','); |
| 569 | EmitItineraryProp(OS, Itin, "LoadLatency", ','); |
| 570 | EmitItineraryProp(OS, Itin, "HighLatency", ' '); |
| 571 | OS << ");\n"; |
| 572 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 573 | // Begin processor itinerary table |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 574 | OS << "\n"; |
Andrew Trick | fc99299 | 2012-06-05 03:44:40 +0000 | [diff] [blame] | 575 | OS << "static const llvm::InstrItinerary " << Name << "Entries" |
| 576 | << "[] = {\n"; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 577 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 578 | // For each itinerary class |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 579 | std::vector<InstrItinerary> &ItinList = *ProcListIter++; |
Andrew Trick | 2348232 | 2011-04-01 02:22:47 +0000 | [diff] [blame] | 580 | assert(ItinList.size() == ItinClassList.size() && "bad itinerary"); |
David Goodwin | 1f52895 | 2009-09-24 20:22:50 +0000 | [diff] [blame] | 581 | for (unsigned j = 0, M = ItinList.size(); j < M; ++j) { |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 582 | InstrItinerary &Intinerary = ItinList[j]; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 583 | |
| 584 | // Emit in the form of |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 585 | // { firstStage, lastStage, firstCycle, lastCycle } // index |
| 586 | if (Intinerary.FirstStage == 0) { |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 587 | OS << " { 1, 0, 0, 0, 0 }"; |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 588 | } else { |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 589 | OS << " { " << |
| 590 | Intinerary.NumMicroOps << ", " << |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 591 | Intinerary.FirstStage << ", " << |
| 592 | Intinerary.LastStage << ", " << |
| 593 | Intinerary.FirstOperandCycle << ", " << |
David Goodwin | fac8541 | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 594 | Intinerary.LastOperandCycle << " }"; |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 595 | } |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 596 | |
Andrew Trick | 2348232 | 2011-04-01 02:22:47 +0000 | [diff] [blame] | 597 | OS << ", // " << j << " " << ItinClassList[j]->getName() << "\n"; |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 598 | } |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 599 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 600 | // End processor itinerary table |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 601 | OS << " { 1, ~0U, ~0U, ~0U, ~0U } // end marker\n"; |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 602 | OS << "};\n"; |
Andrew Trick | fc99299 | 2012-06-05 03:44:40 +0000 | [diff] [blame] | 603 | |
| 604 | OS << '\n'; |
| 605 | OS << "static const llvm::InstrItinerarySubtargetValue " |
| 606 | << Name << " = {\n"; |
| 607 | OS << " &" << Name << "Props,\n"; |
| 608 | OS << " " << Name << "Entries\n"; |
| 609 | OS << "};\n"; |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 610 | } |
Jim Laskey | 10b1dd9 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | // |
| 614 | // EmitProcessorLookup - generate cpu name to itinerary lookup table. |
| 615 | // |
Daniel Dunbar | 1a55180 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 616 | void SubtargetEmitter::EmitProcessorLookup(raw_ostream &OS) { |
Jim Laskey | 10b1dd9 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 617 | // Gather and sort processor information |
| 618 | std::vector<Record*> ProcessorList = |
| 619 | Records.getAllDerivedDefinitions("Processor"); |
Duraid Madina | 42d24c7 | 2005-12-30 14:56:37 +0000 | [diff] [blame] | 620 | std::sort(ProcessorList.begin(), ProcessorList.end(), LessRecordFieldName()); |
Jim Laskey | 10b1dd9 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 621 | |
| 622 | // Begin processor table |
| 623 | OS << "\n"; |
| 624 | OS << "// Sorted (by key) array of itineraries for CPU subtype.\n" |
Benjamin Kramer | 1a2f988 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 625 | << "extern const llvm::SubtargetInfoKV " |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 626 | << Target << "ProcItinKV[] = {\n"; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 627 | |
Jim Laskey | 10b1dd9 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 628 | // For each processor |
| 629 | for (unsigned i = 0, N = ProcessorList.size(); i < N;) { |
| 630 | // Next processor |
| 631 | Record *Processor = ProcessorList[i]; |
| 632 | |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 633 | const std::string &Name = Processor->getValueAsString("Name"); |
| 634 | const std::string &ProcItin = |
| 635 | Processor->getValueAsDef("ProcItin")->getName(); |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 636 | |
Jim Laskey | 10b1dd9 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 637 | // Emit as { "cpu", procinit }, |
| 638 | OS << " { " |
| 639 | << "\"" << Name << "\", " |
| 640 | << "(void *)&" << ProcItin; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 641 | |
Jim Laskey | 10b1dd9 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 642 | OS << " }"; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 643 | |
Jim Laskey | 10b1dd9 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 644 | // Depending on ''if more in the list'' emit comma |
| 645 | if (++i < N) OS << ","; |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 646 | |
Jim Laskey | 10b1dd9 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 647 | OS << "\n"; |
| 648 | } |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 649 | |
Jim Laskey | 10b1dd9 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 650 | // End processor table |
| 651 | OS << "};\n"; |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | // |
| 655 | // EmitData - Emits all stages and itineries, folding common patterns. |
| 656 | // |
Daniel Dunbar | 1a55180 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 657 | void SubtargetEmitter::EmitData(raw_ostream &OS) { |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 658 | std::map<std::string, unsigned> ItinClassesMap; |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 659 | // Gather and sort all itinerary classes |
| 660 | std::vector<Record*> ItinClassList = |
| 661 | Records.getAllDerivedDefinitions("InstrItinClass"); |
| 662 | std::sort(ItinClassList.begin(), ItinClassList.end(), LessRecord()); |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 663 | |
Jim Laskey | 908ae27 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 664 | // Enumerate all the itinerary classes |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 665 | unsigned NItinClasses = CollectAllItinClasses(OS, ItinClassesMap, |
| 666 | ItinClassList); |
Jim Laskey | 6cee630 | 2005-11-01 20:06:59 +0000 | [diff] [blame] | 667 | // Make sure the rest is worth the effort |
Chris Lattner | 387e4bd | 2006-01-27 01:41:55 +0000 | [diff] [blame] | 668 | HasItineraries = NItinClasses != 1; // Ignore NoItinerary. |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 669 | |
Jim Laskey | 6cee630 | 2005-11-01 20:06:59 +0000 | [diff] [blame] | 670 | if (HasItineraries) { |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 671 | std::vector<std::vector<InstrItinerary> > ProcList; |
Jim Laskey | 6cee630 | 2005-11-01 20:06:59 +0000 | [diff] [blame] | 672 | // Emit the stage data |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 673 | EmitStageAndOperandCycleData(OS, NItinClasses, ItinClassesMap, |
| 674 | ItinClassList, ProcList); |
Jim Laskey | 6cee630 | 2005-11-01 20:06:59 +0000 | [diff] [blame] | 675 | // Emit the processor itinerary data |
Andrew Trick | 2348232 | 2011-04-01 02:22:47 +0000 | [diff] [blame] | 676 | EmitProcessorData(OS, ItinClassList, ProcList); |
Jim Laskey | 6cee630 | 2005-11-01 20:06:59 +0000 | [diff] [blame] | 677 | // Emit the processor lookup data |
| 678 | EmitProcessorLookup(OS); |
| 679 | } |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | // |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 683 | // ParseFeaturesFunction - Produces a subtarget specific function for parsing |
| 684 | // the subtarget features string. |
| 685 | // |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 686 | void SubtargetEmitter::ParseFeaturesFunction(raw_ostream &OS, |
| 687 | unsigned NumFeatures, |
| 688 | unsigned NumProcs) { |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 689 | std::vector<Record*> Features = |
| 690 | Records.getAllDerivedDefinitions("SubtargetFeature"); |
Duraid Madina | 42d24c7 | 2005-12-30 14:56:37 +0000 | [diff] [blame] | 691 | std::sort(Features.begin(), Features.end(), LessRecord()); |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 692 | |
Andrew Trick | da96cf2 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 693 | OS << "// ParseSubtargetFeatures - Parses features string setting specified\n" |
| 694 | << "// subtarget options.\n" |
Evan Cheng | 276365d | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 695 | << "void llvm::"; |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 696 | OS << Target; |
Evan Cheng | 0ddff1b | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 697 | OS << "Subtarget::ParseSubtargetFeatures(StringRef CPU, StringRef FS) {\n" |
David Greene | f0fd3af | 2010-01-05 17:47:41 +0000 | [diff] [blame] | 698 | << " DEBUG(dbgs() << \"\\nFeatures:\" << FS);\n" |
Hal Finkel | 3f696e5 | 2012-06-12 04:21:36 +0000 | [diff] [blame] | 699 | << " DEBUG(dbgs() << \"\\nCPU:\" << CPU << \"\\n\\n\");\n"; |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 700 | |
| 701 | if (Features.empty()) { |
| 702 | OS << "}\n"; |
| 703 | return; |
| 704 | } |
| 705 | |
Evan Cheng | 0ddff1b | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 706 | OS << " uint64_t Bits = ReInitMCSubtargetInfo(CPU, FS);\n"; |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 707 | |
Jim Laskey | f7bcde0 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 708 | for (unsigned i = 0; i < Features.size(); i++) { |
| 709 | // Next record |
| 710 | Record *R = Features[i]; |
Bill Wendling | 4222d80 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 711 | const std::string &Instance = R->getName(); |
| 712 | const std::string &Value = R->getValueAsString("Value"); |
| 713 | const std::string &Attribute = R->getValueAsString("Attribute"); |
Evan Cheng | 19c9550 | 2006-01-27 08:09:42 +0000 | [diff] [blame] | 714 | |
Dale Johannesen | db01c8b | 2008-02-14 23:35:16 +0000 | [diff] [blame] | 715 | if (Value=="true" || Value=="false") |
Evan Cheng | 0ddff1b | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 716 | OS << " if ((Bits & " << Target << "::" |
| 717 | << Instance << ") != 0) " |
Dale Johannesen | db01c8b | 2008-02-14 23:35:16 +0000 | [diff] [blame] | 718 | << Attribute << " = " << Value << ";\n"; |
| 719 | else |
Evan Cheng | 0ddff1b | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 720 | OS << " if ((Bits & " << Target << "::" |
| 721 | << Instance << ") != 0 && " |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 722 | << Attribute << " < " << Value << ") " |
| 723 | << Attribute << " = " << Value << ";\n"; |
Jim Laskey | 6cee630 | 2005-11-01 20:06:59 +0000 | [diff] [blame] | 724 | } |
Anton Korobeynikov | 41a0243 | 2009-05-23 19:50:50 +0000 | [diff] [blame] | 725 | |
Evan Cheng | 276365d | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 726 | OS << "}\n"; |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 727 | } |
| 728 | |
Anton Korobeynikov | 41a0243 | 2009-05-23 19:50:50 +0000 | [diff] [blame] | 729 | // |
Jim Laskey | 4bb9cbb | 2005-10-21 19:00:04 +0000 | [diff] [blame] | 730 | // SubtargetEmitter::run - Main subtarget enumeration emitter. |
| 731 | // |
Daniel Dunbar | 1a55180 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 732 | void SubtargetEmitter::run(raw_ostream &OS) { |
Chris Lattner | 67db883 | 2010-12-13 00:23:57 +0000 | [diff] [blame] | 733 | Target = CodeGenTarget(Records).getName(); |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 734 | |
Jakob Stoklund Olesen | 6f36fa9 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 735 | emitSourceFileHeader("Subtarget Enumeration Source Fragment", OS); |
Jim Laskey | 4bb9cbb | 2005-10-21 19:00:04 +0000 | [diff] [blame] | 736 | |
Evan Cheng | ebdeeab | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 737 | OS << "\n#ifdef GET_SUBTARGETINFO_ENUM\n"; |
| 738 | OS << "#undef GET_SUBTARGETINFO_ENUM\n"; |
| 739 | |
| 740 | OS << "namespace llvm {\n"; |
| 741 | Enumeration(OS, "SubtargetFeature", true); |
| 742 | OS << "} // End llvm namespace \n"; |
| 743 | OS << "#endif // GET_SUBTARGETINFO_ENUM\n\n"; |
| 744 | |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 745 | OS << "\n#ifdef GET_SUBTARGETINFO_MC_DESC\n"; |
| 746 | OS << "#undef GET_SUBTARGETINFO_MC_DESC\n"; |
Anton Korobeynikov | 928eb49 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 747 | |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 748 | OS << "namespace llvm {\n"; |
Evan Cheng | c60f9b7 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 749 | #if 0 |
| 750 | OS << "namespace {\n"; |
| 751 | #endif |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 752 | unsigned NumFeatures = FeatureKeyValues(OS); |
Evan Cheng | c60f9b7 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 753 | OS << "\n"; |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 754 | unsigned NumProcs = CPUKeyValues(OS); |
Evan Cheng | c60f9b7 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 755 | OS << "\n"; |
Jim Laskey | 0d841e0 | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 756 | EmitData(OS); |
Evan Cheng | c60f9b7 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 757 | OS << "\n"; |
| 758 | #if 0 |
| 759 | OS << "}\n"; |
| 760 | #endif |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 761 | |
| 762 | // MCInstrInfo initialization routine. |
| 763 | OS << "static inline void Init" << Target |
Evan Cheng | 59ee62d | 2011-07-11 03:57:24 +0000 | [diff] [blame] | 764 | << "MCSubtargetInfo(MCSubtargetInfo *II, " |
| 765 | << "StringRef TT, StringRef CPU, StringRef FS) {\n"; |
| 766 | OS << " II->InitMCSubtargetInfo(TT, CPU, FS, "; |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 767 | if (NumFeatures) |
| 768 | OS << Target << "FeatureKV, "; |
| 769 | else |
| 770 | OS << "0, "; |
| 771 | if (NumProcs) |
| 772 | OS << Target << "SubTypeKV, "; |
| 773 | else |
| 774 | OS << "0, "; |
| 775 | if (HasItineraries) { |
| 776 | OS << Target << "ProcItinKV, " |
| 777 | << Target << "Stages, " |
| 778 | << Target << "OperandCycles, " |
| 779 | << Target << "ForwardingPathes, "; |
| 780 | } else |
| 781 | OS << "0, 0, 0, 0, "; |
| 782 | OS << NumFeatures << ", " << NumProcs << ");\n}\n\n"; |
| 783 | |
| 784 | OS << "} // End llvm namespace \n"; |
| 785 | |
| 786 | OS << "#endif // GET_SUBTARGETINFO_MC_DESC\n\n"; |
| 787 | |
| 788 | OS << "\n#ifdef GET_SUBTARGETINFO_TARGET_DESC\n"; |
| 789 | OS << "#undef GET_SUBTARGETINFO_TARGET_DESC\n"; |
| 790 | |
| 791 | OS << "#include \"llvm/Support/Debug.h\"\n"; |
| 792 | OS << "#include \"llvm/Support/raw_ostream.h\"\n"; |
| 793 | ParseFeaturesFunction(OS, NumFeatures, NumProcs); |
| 794 | |
| 795 | OS << "#endif // GET_SUBTARGETINFO_TARGET_DESC\n\n"; |
| 796 | |
Evan Cheng | 5b1b4489 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 797 | // Create a TargetSubtargetInfo subclass to hide the MC layer initialization. |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 798 | OS << "\n#ifdef GET_SUBTARGETINFO_HEADER\n"; |
| 799 | OS << "#undef GET_SUBTARGETINFO_HEADER\n"; |
| 800 | |
| 801 | std::string ClassName = Target + "GenSubtargetInfo"; |
| 802 | OS << "namespace llvm {\n"; |
Anshuman Dasgupta | dc81e5d | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 803 | OS << "class DFAPacketizer;\n"; |
Evan Cheng | 5b1b4489 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 804 | OS << "struct " << ClassName << " : public TargetSubtargetInfo {\n" |
Evan Cheng | 0ddff1b | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 805 | << " explicit " << ClassName << "(StringRef TT, StringRef CPU, " |
| 806 | << "StringRef FS);\n" |
Anshuman Dasgupta | dc81e5d | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 807 | << "public:\n" |
Sebastian Pop | 464f3a3 | 2011-12-06 17:34:16 +0000 | [diff] [blame] | 808 | << " DFAPacketizer *createDFAPacketizer(const InstrItineraryData *IID)" |
Anshuman Dasgupta | dc81e5d | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 809 | << " const;\n" |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 810 | << "};\n"; |
| 811 | OS << "} // End llvm namespace \n"; |
| 812 | |
| 813 | OS << "#endif // GET_SUBTARGETINFO_HEADER\n\n"; |
| 814 | |
| 815 | OS << "\n#ifdef GET_SUBTARGETINFO_CTOR\n"; |
| 816 | OS << "#undef GET_SUBTARGETINFO_CTOR\n"; |
| 817 | |
| 818 | OS << "namespace llvm {\n"; |
Benjamin Kramer | 1a2f988 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 819 | OS << "extern const llvm::SubtargetFeatureKV " << Target << "FeatureKV[];\n"; |
| 820 | OS << "extern const llvm::SubtargetFeatureKV " << Target << "SubTypeKV[];\n"; |
Evan Cheng | c60f9b7 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 821 | if (HasItineraries) { |
Benjamin Kramer | 1a2f988 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 822 | OS << "extern const llvm::SubtargetInfoKV " << Target << "ProcItinKV[];\n"; |
| 823 | OS << "extern const llvm::InstrStage " << Target << "Stages[];\n"; |
| 824 | OS << "extern const unsigned " << Target << "OperandCycles[];\n"; |
| 825 | OS << "extern const unsigned " << Target << "ForwardingPathes[];\n"; |
Evan Cheng | c60f9b7 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 826 | } |
| 827 | |
Evan Cheng | 0ddff1b | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 828 | OS << ClassName << "::" << ClassName << "(StringRef TT, StringRef CPU, " |
| 829 | << "StringRef FS)\n" |
Evan Cheng | 5b1b4489 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 830 | << " : TargetSubtargetInfo() {\n" |
Evan Cheng | 59ee62d | 2011-07-11 03:57:24 +0000 | [diff] [blame] | 831 | << " InitMCSubtargetInfo(TT, CPU, FS, "; |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 832 | if (NumFeatures) |
| 833 | OS << Target << "FeatureKV, "; |
| 834 | else |
| 835 | OS << "0, "; |
| 836 | if (NumProcs) |
| 837 | OS << Target << "SubTypeKV, "; |
| 838 | else |
| 839 | OS << "0, "; |
| 840 | if (HasItineraries) { |
| 841 | OS << Target << "ProcItinKV, " |
| 842 | << Target << "Stages, " |
| 843 | << Target << "OperandCycles, " |
| 844 | << Target << "ForwardingPathes, "; |
| 845 | } else |
| 846 | OS << "0, 0, 0, 0, "; |
| 847 | OS << NumFeatures << ", " << NumProcs << ");\n}\n\n"; |
| 848 | OS << "} // End llvm namespace \n"; |
| 849 | |
| 850 | OS << "#endif // GET_SUBTARGETINFO_CTOR\n\n"; |
Jim Laskey | 4bb9cbb | 2005-10-21 19:00:04 +0000 | [diff] [blame] | 851 | } |
Jakob Stoklund Olesen | 6f36fa9 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 852 | |
| 853 | namespace llvm { |
| 854 | |
| 855 | void EmitSubtarget(RecordKeeper &RK, raw_ostream &OS) { |
| 856 | SubtargetEmitter(RK).run(OS); |
| 857 | } |
| 858 | |
| 859 | } // End llvm namespace |