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