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