Jim Laskey | cfda85a | 2005-10-21 19:00:04 +0000 | [diff] [blame] | 1 | //===- SubtargetEmitter.cpp - Generate subtarget enumerations -------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Jim Laskey | cfda85a | 2005-10-21 19:00:04 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
Chris Lattner | 73fbe14 | 2006-03-03 02:04:07 +0000 | [diff] [blame] | 9 | // This tablegen backend emits subtarget enumerations. |
Jim Laskey | cfda85a | 2005-10-21 19:00:04 +0000 | [diff] [blame] | 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
Jim Laskey | cfda85a | 2005-10-21 19:00:04 +0000 | [diff] [blame] | 13 | #include "CodeGenTarget.h" |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 14 | #include "CodeGenSchedule.h" |
Andrea Di Biagio | 9514002 | 2018-05-25 15:55:37 +0000 | [diff] [blame] | 15 | #include "PredicateExpander.h" |
Eugene Zelenko | 75259bb | 2016-05-17 17:04:23 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/SmallPtrSet.h" |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/STLExtras.h" |
Chandler Carruth | 91d19d8 | 2012-12-04 10:37:14 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/StringExtras.h" |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/StringRef.h" |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCInstrItineraries.h" |
Eugene Zelenko | 75259bb | 2016-05-17 17:04:23 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCSchedule.h" |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 22 | #include "llvm/MC/SubtargetFeature.h" |
Chandler Carruth | 91d19d8 | 2012-12-04 10:37:14 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Debug.h" |
| 24 | #include "llvm/Support/Format.h" |
Eugene Zelenko | 75259bb | 2016-05-17 17:04:23 +0000 | [diff] [blame] | 25 | #include "llvm/Support/raw_ostream.h" |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 26 | #include "llvm/TableGen/Error.h" |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 27 | #include "llvm/TableGen/Record.h" |
| 28 | #include "llvm/TableGen/TableGenBackend.h" |
Jeff Cohen | b0aa47b | 2005-10-28 01:43:09 +0000 | [diff] [blame] | 29 | #include <algorithm> |
Eugene Zelenko | 75259bb | 2016-05-17 17:04:23 +0000 | [diff] [blame] | 30 | #include <cassert> |
| 31 | #include <cstdint> |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 32 | #include <iterator> |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 33 | #include <map> |
| 34 | #include <string> |
| 35 | #include <vector> |
Hans Wennborg | 083ca9b | 2015-10-06 23:24:35 +0000 | [diff] [blame] | 36 | |
Jim Laskey | cfda85a | 2005-10-21 19:00:04 +0000 | [diff] [blame] | 37 | using namespace llvm; |
| 38 | |
Chandler Carruth | 97acce2 | 2014-04-22 03:06:00 +0000 | [diff] [blame] | 39 | #define DEBUG_TYPE "subtarget-emitter" |
| 40 | |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 41 | namespace { |
Eugene Zelenko | 75259bb | 2016-05-17 17:04:23 +0000 | [diff] [blame] | 42 | |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 43 | class SubtargetEmitter { |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 44 | // Each processor has a SchedClassDesc table with an entry for each SchedClass. |
| 45 | // The SchedClassDesc table indexes into a global write resource table, write |
| 46 | // latency table, and read advance table. |
| 47 | struct SchedClassTables { |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 48 | std::vector<std::vector<MCSchedClassDesc>> ProcSchedClasses; |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 49 | std::vector<MCWriteProcResEntry> WriteProcResources; |
| 50 | std::vector<MCWriteLatencyEntry> WriteLatencies; |
Andrew Trick | cfe222c | 2012-09-19 04:43:19 +0000 | [diff] [blame] | 51 | std::vector<std::string> WriterNames; |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 52 | std::vector<MCReadAdvanceEntry> ReadAdvanceEntries; |
| 53 | |
| 54 | // Reserve an invalid entry at index 0 |
| 55 | SchedClassTables() { |
| 56 | ProcSchedClasses.resize(1); |
| 57 | WriteProcResources.resize(1); |
| 58 | WriteLatencies.resize(1); |
Andrew Trick | cfe222c | 2012-09-19 04:43:19 +0000 | [diff] [blame] | 59 | WriterNames.push_back("InvalidWrite"); |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 60 | ReadAdvanceEntries.resize(1); |
| 61 | } |
| 62 | }; |
| 63 | |
| 64 | struct LessWriteProcResources { |
| 65 | bool operator()(const MCWriteProcResEntry &LHS, |
| 66 | const MCWriteProcResEntry &RHS) { |
| 67 | return LHS.ProcResourceIdx < RHS.ProcResourceIdx; |
| 68 | } |
| 69 | }; |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 70 | |
Krzysztof Parzyszek | 788e768 | 2017-09-14 20:44:20 +0000 | [diff] [blame] | 71 | const CodeGenTarget &TGT; |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 72 | RecordKeeper &Records; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 73 | CodeGenSchedModels &SchedModels; |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 74 | std::string Target; |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 75 | |
Craig Topper | 4f61308 | 2019-03-01 02:19:26 +0000 | [diff] [blame] | 76 | void Enumeration(raw_ostream &OS, DenseMap<Record *, unsigned> &FeatureMap); |
| 77 | unsigned FeatureKeyValues(raw_ostream &OS, |
| 78 | const DenseMap<Record *, unsigned> &FeatureMap); |
| 79 | unsigned CPUKeyValues(raw_ostream &OS, |
| 80 | const DenseMap<Record *, unsigned> &FeatureMap); |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 81 | void FormItineraryStageString(const std::string &Names, |
| 82 | Record *ItinData, std::string &ItinString, |
| 83 | unsigned &NStages); |
| 84 | void FormItineraryOperandCycleString(Record *ItinData, std::string &ItinString, |
| 85 | unsigned &NOperandCycles); |
| 86 | void FormItineraryBypassString(const std::string &Names, |
| 87 | Record *ItinData, |
| 88 | std::string &ItinString, unsigned NOperandCycles); |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 89 | void EmitStageAndOperandCycleData(raw_ostream &OS, |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 90 | std::vector<std::vector<InstrItinerary>> |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 91 | &ProcItinLists); |
| 92 | void EmitItineraries(raw_ostream &OS, |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 93 | std::vector<std::vector<InstrItinerary>> |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 94 | &ProcItinLists); |
Andrea Di Biagio | 378d75a | 2018-04-04 11:53:13 +0000 | [diff] [blame] | 95 | unsigned EmitRegisterFileTables(const CodeGenProcModel &ProcModel, |
| 96 | raw_ostream &OS); |
Andrea Di Biagio | 373a4cc | 2018-11-29 12:15:56 +0000 | [diff] [blame] | 97 | void EmitLoadStoreQueueInfo(const CodeGenProcModel &ProcModel, |
| 98 | raw_ostream &OS); |
Andrea Di Biagio | 378d75a | 2018-04-04 11:53:13 +0000 | [diff] [blame] | 99 | void EmitExtraProcessorInfo(const CodeGenProcModel &ProcModel, |
| 100 | raw_ostream &OS); |
Mehdi Amini | 32986ed | 2016-10-04 23:47:33 +0000 | [diff] [blame] | 101 | void EmitProcessorProp(raw_ostream &OS, const Record *R, StringRef Name, |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 102 | char Separator); |
Clement Courbet | 39911e2 | 2018-02-08 08:46:48 +0000 | [diff] [blame] | 103 | void EmitProcessorResourceSubUnits(const CodeGenProcModel &ProcModel, |
| 104 | raw_ostream &OS); |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 105 | void EmitProcessorResources(const CodeGenProcModel &ProcModel, |
| 106 | raw_ostream &OS); |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 107 | Record *FindWriteResources(const CodeGenSchedRW &SchedWrite, |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 108 | const CodeGenProcModel &ProcModel); |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 109 | Record *FindReadAdvance(const CodeGenSchedRW &SchedRead, |
| 110 | const CodeGenProcModel &ProcModel); |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 111 | void ExpandProcResources(RecVec &PRVec, std::vector<int64_t> &Cycles, |
| 112 | const CodeGenProcModel &ProcModel); |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 113 | void GenSchedClassTables(const CodeGenProcModel &ProcModel, |
| 114 | SchedClassTables &SchedTables); |
Andrew Trick | a72fca6 | 2012-09-17 22:18:50 +0000 | [diff] [blame] | 115 | void EmitSchedClassTables(SchedClassTables &SchedTables, raw_ostream &OS); |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 116 | void EmitProcessorModels(raw_ostream &OS); |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 117 | void EmitProcessorLookup(raw_ostream &OS); |
Benjamin Kramer | c321e53 | 2016-06-08 19:09:22 +0000 | [diff] [blame] | 118 | void EmitSchedModelHelpers(const std::string &ClassName, raw_ostream &OS); |
Andrea Di Biagio | 9514002 | 2018-05-25 15:55:37 +0000 | [diff] [blame] | 119 | void emitSchedModelHelpersImpl(raw_ostream &OS, |
| 120 | bool OnlyExpandMCInstPredicates = false); |
Andrea Di Biagio | 8f66adec | 2018-05-25 16:02:43 +0000 | [diff] [blame] | 121 | void emitGenMCSubtargetInfo(raw_ostream &OS); |
Andrea Di Biagio | 8b6c314 | 2018-09-19 15:57:45 +0000 | [diff] [blame] | 122 | void EmitMCInstrAnalysisPredicateFunctions(raw_ostream &OS); |
Andrea Di Biagio | 9514002 | 2018-05-25 15:55:37 +0000 | [diff] [blame] | 123 | |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 124 | void EmitSchedModel(raw_ostream &OS); |
Krzysztof Parzyszek | 788e768 | 2017-09-14 20:44:20 +0000 | [diff] [blame] | 125 | void EmitHwModeCheck(const std::string &ClassName, raw_ostream &OS); |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 126 | void ParseFeaturesFunction(raw_ostream &OS, unsigned NumFeatures, |
| 127 | unsigned NumProcs); |
| 128 | |
| 129 | public: |
Krzysztof Parzyszek | 788e768 | 2017-09-14 20:44:20 +0000 | [diff] [blame] | 130 | SubtargetEmitter(RecordKeeper &R, CodeGenTarget &TGT) |
| 131 | : TGT(TGT), Records(R), SchedModels(TGT.getSchedModels()), |
| 132 | Target(TGT.getName()) {} |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 133 | |
| 134 | void run(raw_ostream &o); |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 135 | }; |
Eugene Zelenko | 75259bb | 2016-05-17 17:04:23 +0000 | [diff] [blame] | 136 | |
Hans Wennborg | 083ca9b | 2015-10-06 23:24:35 +0000 | [diff] [blame] | 137 | } // end anonymous namespace |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 138 | |
Jim Laskey | a1beea6 | 2005-10-22 07:59:56 +0000 | [diff] [blame] | 139 | // |
Jim Laskey | a2b5235 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 140 | // Enumeration - Emit the specified class as an enumeration. |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 141 | // |
Craig Topper | 4f61308 | 2019-03-01 02:19:26 +0000 | [diff] [blame] | 142 | void SubtargetEmitter::Enumeration(raw_ostream &OS, |
| 143 | DenseMap<Record *, unsigned> &FeatureMap) { |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 144 | // Get all records of class and sort |
Craig Topper | 094bbca | 2016-02-14 05:22:01 +0000 | [diff] [blame] | 145 | std::vector<Record*> DefList = |
| 146 | Records.getAllDerivedDefinitions("SubtargetFeature"); |
Fangrui Song | 0cac726 | 2018-09-27 02:13:45 +0000 | [diff] [blame] | 147 | llvm::sort(DefList, LessRecord()); |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 148 | |
Evan Cheng | a2e6129 | 2011-04-15 19:35:46 +0000 | [diff] [blame] | 149 | unsigned N = DefList.size(); |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 150 | if (N == 0) |
| 151 | return; |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 152 | if (N > MAX_SUBTARGET_FEATURES) |
| 153 | PrintFatalError("Too many subtarget features! Bump MAX_SUBTARGET_FEATURES."); |
Evan Cheng | a2e6129 | 2011-04-15 19:35:46 +0000 | [diff] [blame] | 154 | |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 155 | OS << "namespace " << Target << " {\n"; |
| 156 | |
Craig Topper | bcdb0f2 | 2016-02-13 17:58:14 +0000 | [diff] [blame] | 157 | // Open enumeration. |
Craig Topper | 2d45c1d | 2016-02-13 06:03:29 +0000 | [diff] [blame] | 158 | OS << "enum {\n"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 159 | |
Reid Kleckner | 294fa7a | 2015-03-09 20:23:14 +0000 | [diff] [blame] | 160 | // For each record |
Craig Topper | df1285b | 2017-10-24 15:50:53 +0000 | [diff] [blame] | 161 | for (unsigned i = 0; i < N; ++i) { |
Reid Kleckner | 294fa7a | 2015-03-09 20:23:14 +0000 | [diff] [blame] | 162 | // Next record |
| 163 | Record *Def = DefList[i]; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 164 | |
Reid Kleckner | 294fa7a | 2015-03-09 20:23:14 +0000 | [diff] [blame] | 165 | // Get and emit name |
Craig Topper | df1285b | 2017-10-24 15:50:53 +0000 | [diff] [blame] | 166 | OS << " " << Def->getName() << " = " << i << ",\n"; |
Craig Topper | 4f61308 | 2019-03-01 02:19:26 +0000 | [diff] [blame] | 167 | |
| 168 | // Save the index for this feature. |
| 169 | FeatureMap[Def] = i; |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 170 | } |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 171 | |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 172 | // Close enumeration and namespace |
Eugene Zelenko | 75259bb | 2016-05-17 17:04:23 +0000 | [diff] [blame] | 173 | OS << "};\n"; |
| 174 | OS << "} // end namespace " << Target << "\n"; |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Craig Topper | 4f61308 | 2019-03-01 02:19:26 +0000 | [diff] [blame] | 177 | static void printFeatureMask(raw_ostream &OS, RecVec &FeatureList, |
| 178 | const DenseMap<Record *, unsigned> &FeatureMap) { |
| 179 | std::array<uint64_t, MAX_SUBTARGET_WORDS> Mask = {}; |
| 180 | for (unsigned j = 0, M = FeatureList.size(); j < M; ++j) { |
| 181 | unsigned Bit = FeatureMap.lookup(FeatureList[j]); |
| 182 | Mask[Bit / 64] |= 1ULL << (Bit % 64); |
| 183 | } |
| 184 | |
Craig Topper | 2729a91 | 2019-03-04 19:23:37 +0000 | [diff] [blame] | 185 | OS << "{ { { "; |
Craig Topper | 4f61308 | 2019-03-01 02:19:26 +0000 | [diff] [blame] | 186 | for (unsigned i = 0; i != Mask.size(); ++i) { |
| 187 | OS << "0x"; |
| 188 | OS.write_hex(Mask[i]); |
| 189 | OS << "ULL, "; |
| 190 | } |
Craig Topper | 2729a91 | 2019-03-04 19:23:37 +0000 | [diff] [blame] | 191 | OS << "} } }"; |
Craig Topper | 4f61308 | 2019-03-01 02:19:26 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 194 | // |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 195 | // FeatureKeyValues - Emit data of all the subtarget features. Used by the |
| 196 | // command line. |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 197 | // |
Craig Topper | 4f61308 | 2019-03-01 02:19:26 +0000 | [diff] [blame] | 198 | unsigned SubtargetEmitter::FeatureKeyValues( |
| 199 | raw_ostream &OS, const DenseMap<Record *, unsigned> &FeatureMap) { |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 200 | // Gather and sort all the features |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 201 | std::vector<Record*> FeatureList = |
| 202 | Records.getAllDerivedDefinitions("SubtargetFeature"); |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 203 | |
| 204 | if (FeatureList.empty()) |
| 205 | return 0; |
| 206 | |
Fangrui Song | 0cac726 | 2018-09-27 02:13:45 +0000 | [diff] [blame] | 207 | llvm::sort(FeatureList, LessRecordFieldName()); |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 208 | |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 209 | // Begin feature table |
Jim Laskey | a2b5235 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 210 | OS << "// Sorted (by key) array of values for CPU features.\n" |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 211 | << "extern const llvm::SubtargetFeatureKV " << Target |
| 212 | << "FeatureKV[] = {\n"; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 213 | |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 214 | // For each feature |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 215 | unsigned NumFeatures = 0; |
Jim Laskey | 3f7d047 | 2006-12-12 20:55:58 +0000 | [diff] [blame] | 216 | for (unsigned i = 0, N = FeatureList.size(); i < N; ++i) { |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 217 | // Next feature |
| 218 | Record *Feature = FeatureList[i]; |
| 219 | |
Craig Topper | bcd3c37 | 2017-05-31 21:12:46 +0000 | [diff] [blame] | 220 | StringRef Name = Feature->getName(); |
| 221 | StringRef CommandLineName = Feature->getValueAsString("Name"); |
| 222 | StringRef Desc = Feature->getValueAsString("Desc"); |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 223 | |
Jim Laskey | 3f7d047 | 2006-12-12 20:55:58 +0000 | [diff] [blame] | 224 | if (CommandLineName.empty()) continue; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 225 | |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 226 | // Emit as { "feature", "description", { featureEnum }, { i1 , i2 , ... , in } } |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 227 | OS << " { " |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 228 | << "\"" << CommandLineName << "\", " |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 229 | << "\"" << Desc << "\", " |
Craig Topper | 4cf59aa | 2019-02-18 06:46:17 +0000 | [diff] [blame] | 230 | << Target << "::" << Name << ", "; |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 231 | |
Craig Topper | 37eeb32 | 2018-03-23 00:02:45 +0000 | [diff] [blame] | 232 | RecVec ImpliesList = Feature->getValueAsListOfDefs("Implies"); |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 233 | |
Craig Topper | 4f61308 | 2019-03-01 02:19:26 +0000 | [diff] [blame] | 234 | printFeatureMask(OS, ImpliesList, FeatureMap); |
| 235 | |
| 236 | OS << " },\n"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 237 | ++NumFeatures; |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 238 | } |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 239 | |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 240 | // End feature table |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 241 | OS << "};\n"; |
| 242 | |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 243 | return NumFeatures; |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | // |
| 247 | // CPUKeyValues - Emit data of all the subtarget processors. Used by command |
| 248 | // line. |
| 249 | // |
Craig Topper | 4f61308 | 2019-03-01 02:19:26 +0000 | [diff] [blame] | 250 | unsigned |
| 251 | SubtargetEmitter::CPUKeyValues(raw_ostream &OS, |
| 252 | const DenseMap<Record *, unsigned> &FeatureMap) { |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 253 | // Gather and sort processor information |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 254 | std::vector<Record*> ProcessorList = |
| 255 | Records.getAllDerivedDefinitions("Processor"); |
Fangrui Song | 0cac726 | 2018-09-27 02:13:45 +0000 | [diff] [blame] | 256 | llvm::sort(ProcessorList, LessRecordFieldName()); |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 257 | |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 258 | // Begin processor table |
Jim Laskey | a2b5235 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 259 | OS << "// Sorted (by key) array of values for CPU subtype.\n" |
Craig Topper | ca26808 | 2019-03-05 18:54:34 +0000 | [diff] [blame] | 260 | << "extern const llvm::SubtargetSubTypeKV " << Target |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 261 | << "SubTypeKV[] = {\n"; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 262 | |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 263 | // For each processor |
Craig Topper | df1285b | 2017-10-24 15:50:53 +0000 | [diff] [blame] | 264 | for (Record *Processor : ProcessorList) { |
Craig Topper | bcd3c37 | 2017-05-31 21:12:46 +0000 | [diff] [blame] | 265 | StringRef Name = Processor->getValueAsString("Name"); |
Craig Topper | 37eeb32 | 2018-03-23 00:02:45 +0000 | [diff] [blame] | 266 | RecVec FeatureList = Processor->getValueAsListOfDefs("Features"); |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 267 | |
Craig Topper | 4cf59aa | 2019-02-18 06:46:17 +0000 | [diff] [blame] | 268 | // Emit as { "cpu", "description", 0, { f1 , f2 , ... fn } }, |
Craig Topper | 4cf59aa | 2019-02-18 06:46:17 +0000 | [diff] [blame] | 269 | OS << " { " |
Craig Topper | ca26808 | 2019-03-05 18:54:34 +0000 | [diff] [blame] | 270 | << "\"" << Name << "\", "; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 271 | |
Craig Topper | 4f61308 | 2019-03-01 02:19:26 +0000 | [diff] [blame] | 272 | printFeatureMask(OS, FeatureList, FeatureMap); |
| 273 | |
| 274 | // The {{}} is for the "implies" section of this data structure. |
| 275 | OS << " },\n"; |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 276 | } |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 277 | |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 278 | // End processor table |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 279 | OS << "};\n"; |
| 280 | |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 281 | return ProcessorList.size(); |
Jim Laskey | 1b7369b | 2005-10-25 15:16:36 +0000 | [diff] [blame] | 282 | } |
Jim Laskey | a1beea6 | 2005-10-22 07:59:56 +0000 | [diff] [blame] | 283 | |
Jim Laskey | a2b5235 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 284 | // |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 285 | // FormItineraryStageString - Compose a string containing the stage |
| 286 | // data initialization for the specified itinerary. N is the number |
| 287 | // of stages. |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 288 | // |
Anton Korobeynikov | 7d62e33 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 289 | void SubtargetEmitter::FormItineraryStageString(const std::string &Name, |
| 290 | Record *ItinData, |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 291 | std::string &ItinString, |
| 292 | unsigned &NStages) { |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 293 | // Get states list |
Craig Topper | 37eeb32 | 2018-03-23 00:02:45 +0000 | [diff] [blame] | 294 | RecVec StageList = ItinData->getValueAsListOfDefs("Stages"); |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 295 | |
| 296 | // For each stage |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 297 | unsigned N = NStages = StageList.size(); |
Christopher Lamb | 8996dce | 2007-04-22 09:04:24 +0000 | [diff] [blame] | 298 | for (unsigned i = 0; i < N;) { |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 299 | // Next stage |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 300 | const Record *Stage = StageList[i]; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 301 | |
Anton Korobeynikov | 0bdc634 | 2010-04-07 18:19:32 +0000 | [diff] [blame] | 302 | // Form string as ,{ cycles, u1 | u2 | ... | un, timeinc, kind } |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 303 | int Cycles = Stage->getValueAsInt("Cycles"); |
Jim Laskey | d6d3afb | 2005-11-03 22:47:41 +0000 | [diff] [blame] | 304 | ItinString += " { " + itostr(Cycles) + ", "; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 305 | |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 306 | // Get unit list |
Craig Topper | 37eeb32 | 2018-03-23 00:02:45 +0000 | [diff] [blame] | 307 | RecVec UnitList = Stage->getValueAsListOfDefs("Units"); |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 308 | |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 309 | // For each unit |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 310 | for (unsigned j = 0, M = UnitList.size(); j < M;) { |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 311 | // Add name and bitwise or |
Matthias Braun | 4a86d45 | 2016-12-04 05:48:16 +0000 | [diff] [blame] | 312 | ItinString += Name + "FU::" + UnitList[j]->getName().str(); |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 313 | if (++j < M) ItinString += " | "; |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 314 | } |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 315 | |
David Goodwin | b369ee4 | 2009-08-12 18:31:53 +0000 | [diff] [blame] | 316 | int TimeInc = Stage->getValueAsInt("TimeInc"); |
| 317 | ItinString += ", " + itostr(TimeInc); |
| 318 | |
Anton Korobeynikov | 0bdc634 | 2010-04-07 18:19:32 +0000 | [diff] [blame] | 319 | int Kind = Stage->getValueAsInt("Kind"); |
| 320 | ItinString += ", (llvm::InstrStage::ReservationKinds)" + itostr(Kind); |
| 321 | |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 322 | // Close off stage |
| 323 | ItinString += " }"; |
Christopher Lamb | 8996dce | 2007-04-22 09:04:24 +0000 | [diff] [blame] | 324 | if (++i < N) ItinString += ", "; |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 325 | } |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | // |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 329 | // FormItineraryOperandCycleString - Compose a string containing the |
| 330 | // operand cycle initialization for the specified itinerary. N is the |
| 331 | // number of operands that has cycles specified. |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 332 | // |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 333 | void SubtargetEmitter::FormItineraryOperandCycleString(Record *ItinData, |
| 334 | std::string &ItinString, unsigned &NOperandCycles) { |
| 335 | // Get operand cycle list |
Craig Topper | 37eeb32 | 2018-03-23 00:02:45 +0000 | [diff] [blame] | 336 | std::vector<int64_t> OperandCycleList = |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 337 | ItinData->getValueAsListOfInts("OperandCycles"); |
| 338 | |
| 339 | // For each operand cycle |
| 340 | unsigned N = NOperandCycles = OperandCycleList.size(); |
| 341 | for (unsigned i = 0; i < N;) { |
| 342 | // Next operand cycle |
| 343 | const int OCycle = OperandCycleList[i]; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 344 | |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 345 | ItinString += " " + itostr(OCycle); |
| 346 | if (++i < N) ItinString += ", "; |
| 347 | } |
| 348 | } |
| 349 | |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 350 | void SubtargetEmitter::FormItineraryBypassString(const std::string &Name, |
| 351 | Record *ItinData, |
| 352 | std::string &ItinString, |
| 353 | unsigned NOperandCycles) { |
Craig Topper | 37eeb32 | 2018-03-23 00:02:45 +0000 | [diff] [blame] | 354 | RecVec BypassList = ItinData->getValueAsListOfDefs("Bypasses"); |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 355 | unsigned N = BypassList.size(); |
Evan Cheng | 4a010fd | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 356 | unsigned i = 0; |
| 357 | for (; i < N;) { |
Matthias Braun | 4a86d45 | 2016-12-04 05:48:16 +0000 | [diff] [blame] | 358 | ItinString += Name + "Bypass::" + BypassList[i]->getName().str(); |
Evan Cheng | 4a010fd | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 359 | if (++i < NOperandCycles) ItinString += ", "; |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 360 | } |
Evan Cheng | 4a010fd | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 361 | for (; i < NOperandCycles;) { |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 362 | ItinString += " 0"; |
Evan Cheng | 4a010fd | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 363 | if (++i < NOperandCycles) ItinString += ", "; |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 364 | } |
| 365 | } |
| 366 | |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 367 | // |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 368 | // EmitStageAndOperandCycleData - Generate unique itinerary stages and operand |
| 369 | // cycle tables. Create a list of InstrItinerary objects (ProcItinLists) indexed |
| 370 | // by CodeGenSchedClass::Index. |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 371 | // |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 372 | void SubtargetEmitter:: |
| 373 | EmitStageAndOperandCycleData(raw_ostream &OS, |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 374 | std::vector<std::vector<InstrItinerary>> |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 375 | &ProcItinLists) { |
Andrew Trick | fb982dd | 2012-07-09 20:43:03 +0000 | [diff] [blame] | 376 | // Multiple processor models may share an itinerary record. Emit it once. |
| 377 | SmallPtrSet<Record*, 8> ItinsDefSet; |
| 378 | |
Anton Korobeynikov | 7d62e33 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 379 | // Emit functional units for all the itineraries. |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 380 | for (const CodeGenProcModel &ProcModel : SchedModels.procModels()) { |
Anton Korobeynikov | 7d62e33 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 381 | |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 382 | if (!ItinsDefSet.insert(ProcModel.ItinsDef).second) |
Andrew Trick | fb982dd | 2012-07-09 20:43:03 +0000 | [diff] [blame] | 383 | continue; |
| 384 | |
Craig Topper | 37eeb32 | 2018-03-23 00:02:45 +0000 | [diff] [blame] | 385 | RecVec FUs = ProcModel.ItinsDef->getValueAsListOfDefs("FU"); |
Anton Korobeynikov | 7d62e33 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 386 | if (FUs.empty()) |
| 387 | continue; |
| 388 | |
Alexander Shaposhnikov | d968f6f | 2017-07-05 20:14:54 +0000 | [diff] [blame] | 389 | StringRef Name = ProcModel.ItinsDef->getName(); |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 390 | OS << "\n// Functional units for \"" << Name << "\"\n" |
Anton Korobeynikov | 7d62e33 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 391 | << "namespace " << Name << "FU {\n"; |
| 392 | |
| 393 | for (unsigned j = 0, FUN = FUs.size(); j < FUN; ++j) |
Hal Finkel | 8db5547 | 2012-06-22 20:27:13 +0000 | [diff] [blame] | 394 | OS << " const unsigned " << FUs[j]->getName() |
| 395 | << " = 1 << " << j << ";\n"; |
Anton Korobeynikov | 7d62e33 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 396 | |
Eugene Zelenko | 75259bb | 2016-05-17 17:04:23 +0000 | [diff] [blame] | 397 | OS << "} // end namespace " << Name << "FU\n"; |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 398 | |
Craig Topper | 37eeb32 | 2018-03-23 00:02:45 +0000 | [diff] [blame] | 399 | RecVec BPs = ProcModel.ItinsDef->getValueAsListOfDefs("BP"); |
Alexander Kornienko | 8c0809c | 2015-01-15 11:41:30 +0000 | [diff] [blame] | 400 | if (!BPs.empty()) { |
Sylvestre Ledru | 543f15b | 2018-03-17 17:30:08 +0000 | [diff] [blame] | 401 | OS << "\n// Pipeline forwarding paths for itineraries \"" << Name |
Evan Cheng | 4a010fd | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 402 | << "\"\n" << "namespace " << Name << "Bypass {\n"; |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 403 | |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 404 | OS << " const unsigned NoBypass = 0;\n"; |
Evan Cheng | 4a010fd | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 405 | for (unsigned j = 0, BPN = BPs.size(); j < BPN; ++j) |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 406 | OS << " const unsigned " << BPs[j]->getName() |
Evan Cheng | 4a010fd | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 407 | << " = 1 << " << j << ";\n"; |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 408 | |
Eugene Zelenko | 75259bb | 2016-05-17 17:04:23 +0000 | [diff] [blame] | 409 | OS << "} // end namespace " << Name << "Bypass\n"; |
Evan Cheng | 4a010fd | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 410 | } |
Anton Korobeynikov | 7d62e33 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 411 | } |
| 412 | |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 413 | // Begin stages table |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 414 | std::string StageTable = "\nextern const llvm::InstrStage " + Target + |
| 415 | "Stages[] = {\n"; |
Anton Korobeynikov | 0bdc634 | 2010-04-07 18:19:32 +0000 | [diff] [blame] | 416 | StageTable += " { 0, 0, 0, llvm::InstrStage::Required }, // No itinerary\n"; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 417 | |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 418 | // Begin operand cycle table |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 419 | std::string OperandCycleTable = "extern const unsigned " + Target + |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 420 | "OperandCycles[] = {\n"; |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 421 | OperandCycleTable += " 0, // No itinerary\n"; |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 422 | |
| 423 | // Begin pipeline bypass table |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 424 | std::string BypassTable = "extern const unsigned " + Target + |
Andrew Trick | 030e2f8 | 2012-07-07 03:59:48 +0000 | [diff] [blame] | 425 | "ForwardingPaths[] = {\n"; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 426 | BypassTable += " 0, // No itinerary\n"; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 427 | |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 428 | // For each Itinerary across all processors, add a unique entry to the stages, |
Geoff Berry | b2cfea5 | 2017-05-08 15:33:08 +0000 | [diff] [blame] | 429 | // operand cycles, and pipeline bypass tables. Then add the new Itinerary |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 430 | // object with computed offsets to the ProcItinLists result. |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 431 | unsigned StageCount = 1, OperandCycleCount = 1; |
Evan Cheng | 4a010fd | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 432 | std::map<std::string, unsigned> ItinStageMap, ItinOperandMap; |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 433 | for (const CodeGenProcModel &ProcModel : SchedModels.procModels()) { |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 434 | // Add process itinerary to the list. |
| 435 | ProcItinLists.resize(ProcItinLists.size()+1); |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 436 | |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 437 | // If this processor defines no itineraries, then leave the itinerary list |
| 438 | // empty. |
| 439 | std::vector<InstrItinerary> &ItinList = ProcItinLists.back(); |
Andrew Trick | bf8a28d | 2013-03-16 18:58:55 +0000 | [diff] [blame] | 440 | if (!ProcModel.hasItineraries()) |
Andrew Trick | 9c30267 | 2012-06-22 03:58:51 +0000 | [diff] [blame] | 441 | continue; |
Andrew Trick | 9c30267 | 2012-06-22 03:58:51 +0000 | [diff] [blame] | 442 | |
Alexander Shaposhnikov | d968f6f | 2017-07-05 20:14:54 +0000 | [diff] [blame] | 443 | StringRef Name = ProcModel.ItinsDef->getName(); |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 444 | |
Andrew Trick | bf8a28d | 2013-03-16 18:58:55 +0000 | [diff] [blame] | 445 | ItinList.resize(SchedModels.numInstrSchedClasses()); |
| 446 | assert(ProcModel.ItinDefList.size() == ItinList.size() && "bad Itins"); |
| 447 | |
| 448 | for (unsigned SchedClassIdx = 0, SchedClassEnd = ItinList.size(); |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 449 | SchedClassIdx < SchedClassEnd; ++SchedClassIdx) { |
| 450 | |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 451 | // Next itinerary data |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 452 | Record *ItinData = ProcModel.ItinDefList[SchedClassIdx]; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 453 | |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 454 | // Get string and stage count |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 455 | std::string ItinStageString; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 456 | unsigned NStages = 0; |
| 457 | if (ItinData) |
| 458 | FormItineraryStageString(Name, ItinData, ItinStageString, NStages); |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 459 | |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 460 | // Get string and operand cycle count |
| 461 | std::string ItinOperandCycleString; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 462 | unsigned NOperandCycles = 0; |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 463 | std::string ItinBypassString; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 464 | if (ItinData) { |
| 465 | FormItineraryOperandCycleString(ItinData, ItinOperandCycleString, |
| 466 | NOperandCycles); |
| 467 | |
| 468 | FormItineraryBypassString(Name, ItinData, ItinBypassString, |
| 469 | NOperandCycles); |
| 470 | } |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 471 | |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 472 | // Check to see if stage already exists and create if it doesn't |
Benjamin Kramer | b941aba | 2018-02-23 19:32:56 +0000 | [diff] [blame] | 473 | uint16_t FindStage = 0; |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 474 | if (NStages > 0) { |
| 475 | FindStage = ItinStageMap[ItinStageString]; |
| 476 | if (FindStage == 0) { |
Andrew Trick | 8a05f66 | 2011-04-01 02:22:47 +0000 | [diff] [blame] | 477 | // Emit as { cycles, u1 | u2 | ... | un, timeinc }, // indices |
| 478 | StageTable += ItinStageString + ", // " + itostr(StageCount); |
| 479 | if (NStages > 1) |
| 480 | StageTable += "-" + itostr(StageCount + NStages - 1); |
| 481 | StageTable += "\n"; |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 482 | // Record Itin class number. |
| 483 | ItinStageMap[ItinStageString] = FindStage = StageCount; |
| 484 | StageCount += NStages; |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 485 | } |
| 486 | } |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 487 | |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 488 | // Check to see if operand cycle already exists and create if it doesn't |
Benjamin Kramer | b941aba | 2018-02-23 19:32:56 +0000 | [diff] [blame] | 489 | uint16_t FindOperandCycle = 0; |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 490 | if (NOperandCycles > 0) { |
Evan Cheng | 4a010fd | 2010-09-29 22:42:35 +0000 | [diff] [blame] | 491 | std::string ItinOperandString = ItinOperandCycleString+ItinBypassString; |
| 492 | FindOperandCycle = ItinOperandMap[ItinOperandString]; |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 493 | if (FindOperandCycle == 0) { |
| 494 | // Emit as cycle, // index |
Andrew Trick | 8a05f66 | 2011-04-01 02:22:47 +0000 | [diff] [blame] | 495 | OperandCycleTable += ItinOperandCycleString + ", // "; |
| 496 | std::string OperandIdxComment = itostr(OperandCycleCount); |
| 497 | if (NOperandCycles > 1) |
| 498 | OperandIdxComment += "-" |
| 499 | + itostr(OperandCycleCount + NOperandCycles - 1); |
| 500 | OperandCycleTable += OperandIdxComment + "\n"; |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 501 | // Record Itin class number. |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 502 | ItinOperandMap[ItinOperandCycleString] = |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 503 | FindOperandCycle = OperandCycleCount; |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 504 | // Emit as bypass, // index |
Andrew Trick | 8a05f66 | 2011-04-01 02:22:47 +0000 | [diff] [blame] | 505 | BypassTable += ItinBypassString + ", // " + OperandIdxComment + "\n"; |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 506 | OperandCycleCount += NOperandCycles; |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 507 | } |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 508 | } |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 509 | |
Evan Cheng | 367a5df | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 510 | // Set up itinerary as location and location + stage count |
Benjamin Kramer | b941aba | 2018-02-23 19:32:56 +0000 | [diff] [blame] | 511 | int16_t NumUOps = ItinData ? ItinData->getValueAsInt("NumMicroOps") : 0; |
| 512 | InstrItinerary Intinerary = { |
| 513 | NumUOps, |
| 514 | FindStage, |
| 515 | uint16_t(FindStage + NStages), |
| 516 | FindOperandCycle, |
| 517 | uint16_t(FindOperandCycle + NOperandCycles), |
| 518 | }; |
Evan Cheng | 367a5df | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 519 | |
Jim Laskey | 1959575 | 2005-10-28 15:20:43 +0000 | [diff] [blame] | 520 | // Inject - empty slots will be 0, 0 |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 521 | ItinList[SchedClassIdx] = Intinerary; |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 522 | } |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 523 | } |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 524 | |
Jim Laskey | d6d3afb | 2005-11-03 22:47:41 +0000 | [diff] [blame] | 525 | // Closing stage |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 526 | StageTable += " { 0, 0, 0, llvm::InstrStage::Required } // End stages\n"; |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 527 | StageTable += "};\n"; |
| 528 | |
| 529 | // Closing operand cycles |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 530 | OperandCycleTable += " 0 // End operand cycles\n"; |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 531 | OperandCycleTable += "};\n"; |
| 532 | |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 533 | BypassTable += " 0 // End bypass tables\n"; |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 534 | BypassTable += "};\n"; |
| 535 | |
David Goodwin | d813cbf | 2009-08-17 16:02:57 +0000 | [diff] [blame] | 536 | // Emit tables. |
| 537 | OS << StageTable; |
| 538 | OS << OperandCycleTable; |
Evan Cheng | 0097dd0 | 2010-09-28 23:50:49 +0000 | [diff] [blame] | 539 | OS << BypassTable; |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 540 | } |
| 541 | |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 542 | // |
| 543 | // EmitProcessorData - Generate data for processor itineraries that were |
| 544 | // computed during EmitStageAndOperandCycleData(). ProcItinLists lists all |
| 545 | // Itineraries for each processor. The Itinerary lists are indexed on |
| 546 | // CodeGenSchedClass::Index. |
| 547 | // |
| 548 | void SubtargetEmitter:: |
| 549 | EmitItineraries(raw_ostream &OS, |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 550 | std::vector<std::vector<InstrItinerary>> &ProcItinLists) { |
Andrew Trick | fb982dd | 2012-07-09 20:43:03 +0000 | [diff] [blame] | 551 | // Multiple processor models may share an itinerary record. Emit it once. |
| 552 | SmallPtrSet<Record*, 8> ItinsDefSet; |
| 553 | |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 554 | // For each processor's machine model |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 555 | std::vector<std::vector<InstrItinerary>>::iterator |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 556 | ProcItinListsIter = ProcItinLists.begin(); |
| 557 | for (CodeGenSchedModels::ProcIter PI = SchedModels.procModelBegin(), |
Andrew Trick | 7668649 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 558 | PE = SchedModels.procModelEnd(); PI != PE; ++PI, ++ProcItinListsIter) { |
Andrew Trick | fb982dd | 2012-07-09 20:43:03 +0000 | [diff] [blame] | 559 | |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 560 | Record *ItinsDef = PI->ItinsDef; |
David Blaikie | 70573dc | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 561 | if (!ItinsDefSet.insert(ItinsDef).second) |
Andrew Trick | fb982dd | 2012-07-09 20:43:03 +0000 | [diff] [blame] | 562 | continue; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 563 | |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 564 | // Get the itinerary list for the processor. |
| 565 | assert(ProcItinListsIter != ProcItinLists.end() && "bad iterator"); |
Andrew Trick | 7668649 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 566 | std::vector<InstrItinerary> &ItinList = *ProcItinListsIter; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 567 | |
Pete Cooper | c0eb153 | 2014-09-02 23:23:34 +0000 | [diff] [blame] | 568 | // Empty itineraries aren't referenced anywhere in the tablegen output |
| 569 | // so don't emit them. |
| 570 | if (ItinList.empty()) |
| 571 | continue; |
| 572 | |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 573 | OS << "\n"; |
| 574 | OS << "static const llvm::InstrItinerary "; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 575 | |
| 576 | // Begin processor itinerary table |
Alexander Shaposhnikov | d968f6f | 2017-07-05 20:14:54 +0000 | [diff] [blame] | 577 | OS << ItinsDef->getName() << "[] = {\n"; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 578 | |
| 579 | // For each itinerary class in CodeGenSchedClass::Index order. |
| 580 | for (unsigned j = 0, M = ItinList.size(); j < M; ++j) { |
| 581 | InstrItinerary &Intinerary = ItinList[j]; |
| 582 | |
| 583 | // Emit Itinerary in the form of |
| 584 | // { firstStage, lastStage, firstCycle, lastCycle } // index |
| 585 | OS << " { " << |
| 586 | Intinerary.NumMicroOps << ", " << |
| 587 | Intinerary.FirstStage << ", " << |
| 588 | Intinerary.LastStage << ", " << |
| 589 | Intinerary.FirstOperandCycle << ", " << |
| 590 | Intinerary.LastOperandCycle << " }" << |
| 591 | ", // " << j << " " << SchedModels.getSchedClass(j).Name << "\n"; |
| 592 | } |
| 593 | // End processor itinerary table |
Benjamin Kramer | b941aba | 2018-02-23 19:32:56 +0000 | [diff] [blame] | 594 | OS << " { 0, uint16_t(~0U), uint16_t(~0U), uint16_t(~0U), uint16_t(~0U) }" |
| 595 | "// end marker\n"; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 596 | OS << "};\n"; |
| 597 | } |
| 598 | } |
| 599 | |
Sylvestre Ledru | 35521e2 | 2012-07-23 08:51:15 +0000 | [diff] [blame] | 600 | // Emit either the value defined in the TableGen Record, or the default |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 601 | // value defined in the C++ header. The Record is null if the processor does not |
| 602 | // define a model. |
| 603 | void SubtargetEmitter::EmitProcessorProp(raw_ostream &OS, const Record *R, |
Mehdi Amini | 32986ed | 2016-10-04 23:47:33 +0000 | [diff] [blame] | 604 | StringRef Name, char Separator) { |
Andrew Trick | 73d7736 | 2012-06-05 03:44:40 +0000 | [diff] [blame] | 605 | OS << " "; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 606 | int V = R ? R->getValueAsInt(Name) : -1; |
Andrew Trick | 73d7736 | 2012-06-05 03:44:40 +0000 | [diff] [blame] | 607 | if (V >= 0) |
| 608 | OS << V << Separator << " // " << Name; |
| 609 | else |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 610 | OS << "MCSchedModel::Default" << Name << Separator; |
Andrew Trick | 73d7736 | 2012-06-05 03:44:40 +0000 | [diff] [blame] | 611 | OS << '\n'; |
| 612 | } |
| 613 | |
Clement Courbet | 39911e2 | 2018-02-08 08:46:48 +0000 | [diff] [blame] | 614 | void SubtargetEmitter::EmitProcessorResourceSubUnits( |
| 615 | const CodeGenProcModel &ProcModel, raw_ostream &OS) { |
| 616 | OS << "\nstatic const unsigned " << ProcModel.ModelName |
| 617 | << "ProcResourceSubUnits[] = {\n" |
| 618 | << " 0, // Invalid\n"; |
| 619 | |
| 620 | for (unsigned i = 0, e = ProcModel.ProcResourceDefs.size(); i < e; ++i) { |
| 621 | Record *PRDef = ProcModel.ProcResourceDefs[i]; |
| 622 | if (!PRDef->isSubClassOf("ProcResGroup")) |
| 623 | continue; |
| 624 | RecVec ResUnits = PRDef->getValueAsListOfDefs("Resources"); |
| 625 | for (Record *RUDef : ResUnits) { |
| 626 | Record *const RU = |
| 627 | SchedModels.findProcResUnits(RUDef, ProcModel, PRDef->getLoc()); |
| 628 | for (unsigned J = 0; J < RU->getValueAsInt("NumUnits"); ++J) { |
| 629 | OS << " " << ProcModel.getProcResourceIdx(RU) << ", "; |
| 630 | } |
| 631 | } |
| 632 | OS << " // " << PRDef->getName() << "\n"; |
| 633 | } |
| 634 | OS << "};\n"; |
| 635 | } |
| 636 | |
Andrea Di Biagio | c74ad50 | 2018-04-05 15:41:41 +0000 | [diff] [blame] | 637 | static void EmitRetireControlUnitInfo(const CodeGenProcModel &ProcModel, |
| 638 | raw_ostream &OS) { |
Andrea Di Biagio | 9730bb8 | 2018-04-05 15:53:31 +0000 | [diff] [blame] | 639 | int64_t ReorderBufferSize = 0, MaxRetirePerCycle = 0; |
Andrea Di Biagio | c74ad50 | 2018-04-05 15:41:41 +0000 | [diff] [blame] | 640 | if (Record *RCU = ProcModel.RetireControlUnit) { |
| 641 | ReorderBufferSize = |
| 642 | std::max(ReorderBufferSize, RCU->getValueAsInt("ReorderBufferSize")); |
| 643 | MaxRetirePerCycle = |
| 644 | std::max(MaxRetirePerCycle, RCU->getValueAsInt("MaxRetirePerCycle")); |
| 645 | } |
| 646 | |
| 647 | OS << ReorderBufferSize << ", // ReorderBufferSize\n "; |
| 648 | OS << MaxRetirePerCycle << ", // MaxRetirePerCycle\n "; |
| 649 | } |
| 650 | |
Andrea Di Biagio | 378d75a | 2018-04-04 11:53:13 +0000 | [diff] [blame] | 651 | static void EmitRegisterFileInfo(const CodeGenProcModel &ProcModel, |
| 652 | unsigned NumRegisterFiles, |
| 653 | unsigned NumCostEntries, raw_ostream &OS) { |
| 654 | if (NumRegisterFiles) |
| 655 | OS << ProcModel.ModelName << "RegisterFiles,\n " << (1 + NumRegisterFiles); |
| 656 | else |
Andrea Di Biagio | 8fd4be3 | 2018-04-05 13:59:52 +0000 | [diff] [blame] | 657 | OS << "nullptr,\n 0"; |
Andrea Di Biagio | 378d75a | 2018-04-04 11:53:13 +0000 | [diff] [blame] | 658 | |
| 659 | OS << ", // Number of register files.\n "; |
| 660 | if (NumCostEntries) |
| 661 | OS << ProcModel.ModelName << "RegisterCosts,\n "; |
| 662 | else |
Andrea Di Biagio | 8fd4be3 | 2018-04-05 13:59:52 +0000 | [diff] [blame] | 663 | OS << "nullptr,\n "; |
Clement Courbet | b449379 | 2018-04-10 08:16:37 +0000 | [diff] [blame] | 664 | OS << NumCostEntries << ", // Number of register cost entries.\n"; |
Andrea Di Biagio | 378d75a | 2018-04-04 11:53:13 +0000 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | unsigned |
| 668 | SubtargetEmitter::EmitRegisterFileTables(const CodeGenProcModel &ProcModel, |
| 669 | raw_ostream &OS) { |
Andrea Di Biagio | 9da4d6d | 2018-04-03 13:36:24 +0000 | [diff] [blame] | 670 | if (llvm::all_of(ProcModel.RegisterFiles, [](const CodeGenRegisterFile &RF) { |
| 671 | return RF.hasDefaultCosts(); |
| 672 | })) |
Andrea Di Biagio | 378d75a | 2018-04-04 11:53:13 +0000 | [diff] [blame] | 673 | return 0; |
Andrea Di Biagio | 9da4d6d | 2018-04-03 13:36:24 +0000 | [diff] [blame] | 674 | |
| 675 | // Print the RegisterCost table first. |
Andrea Di Biagio | 6eebbe0 | 2018-10-12 11:23:04 +0000 | [diff] [blame] | 676 | OS << "\n// {RegisterClassID, Register Cost, AllowMoveElimination }\n"; |
Andrea Di Biagio | 9da4d6d | 2018-04-03 13:36:24 +0000 | [diff] [blame] | 677 | OS << "static const llvm::MCRegisterCostEntry " << ProcModel.ModelName |
| 678 | << "RegisterCosts" |
| 679 | << "[] = {\n"; |
| 680 | |
| 681 | for (const CodeGenRegisterFile &RF : ProcModel.RegisterFiles) { |
| 682 | // Skip register files with a default cost table. |
| 683 | if (RF.hasDefaultCosts()) |
| 684 | continue; |
| 685 | // Add entries to the cost table. |
| 686 | for (const CodeGenRegisterCost &RC : RF.Costs) { |
| 687 | OS << " { "; |
| 688 | Record *Rec = RC.RCDef; |
| 689 | if (Rec->getValue("Namespace")) |
| 690 | OS << Rec->getValueAsString("Namespace") << "::"; |
Andrea Di Biagio | 6eebbe0 | 2018-10-12 11:23:04 +0000 | [diff] [blame] | 691 | OS << Rec->getName() << "RegClassID, " << RC.Cost << ", " |
| 692 | << RC.AllowMoveElimination << "},\n"; |
Andrea Di Biagio | 9da4d6d | 2018-04-03 13:36:24 +0000 | [diff] [blame] | 693 | } |
| 694 | } |
| 695 | OS << "};\n"; |
| 696 | |
| 697 | // Now generate a table with register file info. |
Andrea Di Biagio | 6eebbe0 | 2018-10-12 11:23:04 +0000 | [diff] [blame] | 698 | OS << "\n // {Name, #PhysRegs, #CostEntries, IndexToCostTbl, " |
| 699 | << "MaxMovesEliminatedPerCycle, AllowZeroMoveEliminationOnly }\n"; |
Andrea Di Biagio | 9da4d6d | 2018-04-03 13:36:24 +0000 | [diff] [blame] | 700 | OS << "static const llvm::MCRegisterFileDesc " << ProcModel.ModelName |
| 701 | << "RegisterFiles" |
| 702 | << "[] = {\n" |
Andrea Di Biagio | 6eebbe0 | 2018-10-12 11:23:04 +0000 | [diff] [blame] | 703 | << " { \"InvalidRegisterFile\", 0, 0, 0, 0, 0 },\n"; |
Andrea Di Biagio | 9da4d6d | 2018-04-03 13:36:24 +0000 | [diff] [blame] | 704 | unsigned CostTblIndex = 0; |
| 705 | |
| 706 | for (const CodeGenRegisterFile &RD : ProcModel.RegisterFiles) { |
| 707 | OS << " { "; |
| 708 | OS << '"' << RD.Name << '"' << ", " << RD.NumPhysRegs << ", "; |
| 709 | unsigned NumCostEntries = RD.Costs.size(); |
Andrea Di Biagio | 6eebbe0 | 2018-10-12 11:23:04 +0000 | [diff] [blame] | 710 | OS << NumCostEntries << ", " << CostTblIndex << ", " |
| 711 | << RD.MaxMovesEliminatedPerCycle << ", " |
| 712 | << RD.AllowZeroMoveEliminationOnly << "},\n"; |
Andrea Di Biagio | 9da4d6d | 2018-04-03 13:36:24 +0000 | [diff] [blame] | 713 | CostTblIndex += NumCostEntries; |
| 714 | } |
| 715 | OS << "};\n"; |
| 716 | |
Andrea Di Biagio | 378d75a | 2018-04-04 11:53:13 +0000 | [diff] [blame] | 717 | return CostTblIndex; |
| 718 | } |
Simon Pilgrim | b04cd1b | 2018-04-19 10:59:49 +0000 | [diff] [blame] | 719 | |
Andrea Di Biagio | 373a4cc | 2018-11-29 12:15:56 +0000 | [diff] [blame] | 720 | void SubtargetEmitter::EmitLoadStoreQueueInfo(const CodeGenProcModel &ProcModel, |
| 721 | raw_ostream &OS) { |
| 722 | unsigned QueueID = 0; |
| 723 | if (ProcModel.LoadQueue) { |
| 724 | const Record *Queue = ProcModel.LoadQueue->getValueAsDef("QueueDescriptor"); |
| 725 | QueueID = |
| 726 | 1 + std::distance(ProcModel.ProcResourceDefs.begin(), |
| 727 | std::find(ProcModel.ProcResourceDefs.begin(), |
| 728 | ProcModel.ProcResourceDefs.end(), Queue)); |
| 729 | } |
| 730 | OS << " " << QueueID << ", // Resource Descriptor for the Load Queue\n"; |
| 731 | |
| 732 | QueueID = 0; |
| 733 | if (ProcModel.StoreQueue) { |
| 734 | const Record *Queue = |
| 735 | ProcModel.StoreQueue->getValueAsDef("QueueDescriptor"); |
| 736 | QueueID = |
| 737 | 1 + std::distance(ProcModel.ProcResourceDefs.begin(), |
| 738 | std::find(ProcModel.ProcResourceDefs.begin(), |
| 739 | ProcModel.ProcResourceDefs.end(), Queue)); |
| 740 | } |
| 741 | OS << " " << QueueID << ", // Resource Descriptor for the Store Queue\n"; |
| 742 | } |
| 743 | |
Andrea Di Biagio | 378d75a | 2018-04-04 11:53:13 +0000 | [diff] [blame] | 744 | void SubtargetEmitter::EmitExtraProcessorInfo(const CodeGenProcModel &ProcModel, |
| 745 | raw_ostream &OS) { |
| 746 | // Generate a table of register file descriptors (one entry per each user |
| 747 | // defined register file), and a table of register costs. |
| 748 | unsigned NumCostEntries = EmitRegisterFileTables(ProcModel, OS); |
| 749 | |
Andrea Di Biagio | 9da4d6d | 2018-04-03 13:36:24 +0000 | [diff] [blame] | 750 | // Now generate a table for the extra processor info. |
| 751 | OS << "\nstatic const llvm::MCExtraProcessorInfo " << ProcModel.ModelName |
Andrea Di Biagio | 378d75a | 2018-04-04 11:53:13 +0000 | [diff] [blame] | 752 | << "ExtraInfo = {\n "; |
| 753 | |
Andrea Di Biagio | c74ad50 | 2018-04-05 15:41:41 +0000 | [diff] [blame] | 754 | // Add information related to the retire control unit. |
| 755 | EmitRetireControlUnitInfo(ProcModel, OS); |
| 756 | |
Andrea Di Biagio | 378d75a | 2018-04-04 11:53:13 +0000 | [diff] [blame] | 757 | // Add information related to the register files (i.e. where to find register |
| 758 | // file descriptors and register costs). |
| 759 | EmitRegisterFileInfo(ProcModel, ProcModel.RegisterFiles.size(), |
| 760 | NumCostEntries, OS); |
| 761 | |
Andrea Di Biagio | 373a4cc | 2018-11-29 12:15:56 +0000 | [diff] [blame] | 762 | // Add information about load/store queues. |
| 763 | EmitLoadStoreQueueInfo(ProcModel, OS); |
| 764 | |
Andrea Di Biagio | 378d75a | 2018-04-04 11:53:13 +0000 | [diff] [blame] | 765 | OS << "};\n"; |
Andrea Di Biagio | 9da4d6d | 2018-04-03 13:36:24 +0000 | [diff] [blame] | 766 | } |
| 767 | |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 768 | void SubtargetEmitter::EmitProcessorResources(const CodeGenProcModel &ProcModel, |
| 769 | raw_ostream &OS) { |
Clement Courbet | 39911e2 | 2018-02-08 08:46:48 +0000 | [diff] [blame] | 770 | EmitProcessorResourceSubUnits(ProcModel, OS); |
| 771 | |
Jinsong Ji | 0594162 | 2018-09-18 15:38:56 +0000 | [diff] [blame] | 772 | OS << "\n// {Name, NumUnits, SuperIdx, BufferSize, SubUnitsIdxBegin}\n"; |
David Blaikie | e6503d8 | 2018-02-08 19:57:05 +0000 | [diff] [blame] | 773 | OS << "static const llvm::MCProcResourceDesc " << ProcModel.ModelName |
| 774 | << "ProcResources" |
| 775 | << "[] = {\n" |
Andrea Di Biagio | 30e9402 | 2018-03-08 10:38:45 +0000 | [diff] [blame] | 776 | << " {\"InvalidUnit\", 0, 0, 0, 0},\n"; |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 777 | |
Clement Courbet | 39911e2 | 2018-02-08 08:46:48 +0000 | [diff] [blame] | 778 | unsigned SubUnitsOffset = 1; |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 779 | for (unsigned i = 0, e = ProcModel.ProcResourceDefs.size(); i < e; ++i) { |
| 780 | Record *PRDef = ProcModel.ProcResourceDefs[i]; |
| 781 | |
Craig Topper | 2406477 | 2014-04-15 07:20:03 +0000 | [diff] [blame] | 782 | Record *SuperDef = nullptr; |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 783 | unsigned SuperIdx = 0; |
| 784 | unsigned NumUnits = 0; |
Clement Courbet | 39911e2 | 2018-02-08 08:46:48 +0000 | [diff] [blame] | 785 | const unsigned SubUnitsBeginOffset = SubUnitsOffset; |
Andrew Trick | 40c4f38 | 2013-06-15 04:50:06 +0000 | [diff] [blame] | 786 | int BufferSize = PRDef->getValueAsInt("BufferSize"); |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 787 | if (PRDef->isSubClassOf("ProcResGroup")) { |
| 788 | RecVec ResUnits = PRDef->getValueAsListOfDefs("Resources"); |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 789 | for (Record *RU : ResUnits) { |
| 790 | NumUnits += RU->getValueAsInt("NumUnits"); |
Clement Courbet | 873aa11 | 2018-02-09 10:28:46 +0000 | [diff] [blame] | 791 | SubUnitsOffset += RU->getValueAsInt("NumUnits"); |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 792 | } |
| 793 | } |
| 794 | else { |
| 795 | // Find the SuperIdx |
| 796 | if (PRDef->getValueInit("Super")->isComplete()) { |
Evandro Menezes | 9dc54e2 | 2017-11-21 21:33:52 +0000 | [diff] [blame] | 797 | SuperDef = |
| 798 | SchedModels.findProcResUnits(PRDef->getValueAsDef("Super"), |
| 799 | ProcModel, PRDef->getLoc()); |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 800 | SuperIdx = ProcModel.getProcResourceIdx(SuperDef); |
| 801 | } |
Andrew Trick | a5c747b | 2013-03-14 22:47:01 +0000 | [diff] [blame] | 802 | NumUnits = PRDef->getValueAsInt("NumUnits"); |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 803 | } |
| 804 | // Emit the ProcResourceDesc |
Andrea Di Biagio | 30e9402 | 2018-03-08 10:38:45 +0000 | [diff] [blame] | 805 | OS << " {\"" << PRDef->getName() << "\", "; |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 806 | if (PRDef->getName().size() < 15) |
| 807 | OS.indent(15 - PRDef->getName().size()); |
Clement Courbet | 39911e2 | 2018-02-08 08:46:48 +0000 | [diff] [blame] | 808 | OS << NumUnits << ", " << SuperIdx << ", " << BufferSize << ", "; |
| 809 | if (SubUnitsBeginOffset != SubUnitsOffset) { |
| 810 | OS << ProcModel.ModelName << "ProcResourceSubUnits + " |
| 811 | << SubUnitsBeginOffset; |
| 812 | } else { |
| 813 | OS << "nullptr"; |
| 814 | } |
| 815 | OS << "}, // #" << i+1; |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 816 | if (SuperDef) |
| 817 | OS << ", Super=" << SuperDef->getName(); |
| 818 | OS << "\n"; |
| 819 | } |
| 820 | OS << "};\n"; |
| 821 | } |
| 822 | |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 823 | // Find the WriteRes Record that defines processor resources for this |
| 824 | // SchedWrite. |
| 825 | Record *SubtargetEmitter::FindWriteResources( |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 826 | const CodeGenSchedRW &SchedWrite, const CodeGenProcModel &ProcModel) { |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 827 | |
| 828 | // Check if the SchedWrite is already subtarget-specific and directly |
| 829 | // specifies a set of processor resources. |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 830 | if (SchedWrite.TheDef->isSubClassOf("SchedWriteRes")) |
| 831 | return SchedWrite.TheDef; |
| 832 | |
Craig Topper | 2406477 | 2014-04-15 07:20:03 +0000 | [diff] [blame] | 833 | Record *AliasDef = nullptr; |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 834 | for (Record *A : SchedWrite.Aliases) { |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 835 | const CodeGenSchedRW &AliasRW = |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 836 | SchedModels.getSchedRW(A->getValueAsDef("AliasRW")); |
Andrew Trick | da984b1 | 2012-10-03 23:06:28 +0000 | [diff] [blame] | 837 | if (AliasRW.TheDef->getValueInit("SchedModel")->isComplete()) { |
| 838 | Record *ModelDef = AliasRW.TheDef->getValueAsDef("SchedModel"); |
| 839 | if (&SchedModels.getProcModel(ModelDef) != &ProcModel) |
| 840 | continue; |
| 841 | } |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 842 | if (AliasDef) |
Joerg Sonnenberger | 635debe | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 843 | PrintFatalError(AliasRW.TheDef->getLoc(), "Multiple aliases " |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 844 | "defined for processor " + ProcModel.ModelName + |
| 845 | " Ensure only one SchedAlias exists per RW."); |
| 846 | AliasDef = AliasRW.TheDef; |
| 847 | } |
| 848 | if (AliasDef && AliasDef->isSubClassOf("SchedWriteRes")) |
| 849 | return AliasDef; |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 850 | |
| 851 | // Check this processor's list of write resources. |
Craig Topper | 2406477 | 2014-04-15 07:20:03 +0000 | [diff] [blame] | 852 | Record *ResDef = nullptr; |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 853 | for (Record *WR : ProcModel.WriteResDefs) { |
| 854 | if (!WR->isSubClassOf("WriteRes")) |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 855 | continue; |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 856 | if (AliasDef == WR->getValueAsDef("WriteType") |
| 857 | || SchedWrite.TheDef == WR->getValueAsDef("WriteType")) { |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 858 | if (ResDef) { |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 859 | PrintFatalError(WR->getLoc(), "Resources are defined for both " |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 860 | "SchedWrite and its alias on processor " + |
| 861 | ProcModel.ModelName); |
| 862 | } |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 863 | ResDef = WR; |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 864 | } |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 865 | } |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 866 | // TODO: If ProcModel has a base model (previous generation processor), |
| 867 | // then call FindWriteResources recursively with that model here. |
| 868 | if (!ResDef) { |
Joerg Sonnenberger | 635debe | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 869 | PrintFatalError(ProcModel.ModelDef->getLoc(), |
Craig Topper | 01ebd9b | 2017-10-26 20:49:36 +0000 | [diff] [blame] | 870 | Twine("Processor does not define resources for ") + |
| 871 | SchedWrite.TheDef->getName()); |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 872 | } |
| 873 | return ResDef; |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | /// Find the ReadAdvance record for the given SchedRead on this processor or |
| 877 | /// return NULL. |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 878 | Record *SubtargetEmitter::FindReadAdvance(const CodeGenSchedRW &SchedRead, |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 879 | const CodeGenProcModel &ProcModel) { |
| 880 | // Check for SchedReads that directly specify a ReadAdvance. |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 881 | if (SchedRead.TheDef->isSubClassOf("SchedReadAdvance")) |
| 882 | return SchedRead.TheDef; |
| 883 | |
| 884 | // Check this processor's list of aliases for SchedRead. |
Craig Topper | 2406477 | 2014-04-15 07:20:03 +0000 | [diff] [blame] | 885 | Record *AliasDef = nullptr; |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 886 | for (Record *A : SchedRead.Aliases) { |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 887 | const CodeGenSchedRW &AliasRW = |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 888 | SchedModels.getSchedRW(A->getValueAsDef("AliasRW")); |
Andrew Trick | da984b1 | 2012-10-03 23:06:28 +0000 | [diff] [blame] | 889 | if (AliasRW.TheDef->getValueInit("SchedModel")->isComplete()) { |
| 890 | Record *ModelDef = AliasRW.TheDef->getValueAsDef("SchedModel"); |
| 891 | if (&SchedModels.getProcModel(ModelDef) != &ProcModel) |
| 892 | continue; |
| 893 | } |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 894 | if (AliasDef) |
Joerg Sonnenberger | 635debe | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 895 | PrintFatalError(AliasRW.TheDef->getLoc(), "Multiple aliases " |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 896 | "defined for processor " + ProcModel.ModelName + |
| 897 | " Ensure only one SchedAlias exists per RW."); |
| 898 | AliasDef = AliasRW.TheDef; |
| 899 | } |
| 900 | if (AliasDef && AliasDef->isSubClassOf("SchedReadAdvance")) |
| 901 | return AliasDef; |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 902 | |
| 903 | // Check this processor's ReadAdvanceList. |
Craig Topper | 2406477 | 2014-04-15 07:20:03 +0000 | [diff] [blame] | 904 | Record *ResDef = nullptr; |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 905 | for (Record *RA : ProcModel.ReadAdvanceDefs) { |
| 906 | if (!RA->isSubClassOf("ReadAdvance")) |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 907 | continue; |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 908 | if (AliasDef == RA->getValueAsDef("ReadType") |
| 909 | || SchedRead.TheDef == RA->getValueAsDef("ReadType")) { |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 910 | if (ResDef) { |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 911 | PrintFatalError(RA->getLoc(), "Resources are defined for both " |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 912 | "SchedRead and its alias on processor " + |
| 913 | ProcModel.ModelName); |
| 914 | } |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 915 | ResDef = RA; |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 916 | } |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 917 | } |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 918 | // TODO: If ProcModel has a base model (previous generation processor), |
| 919 | // then call FindReadAdvance recursively with that model here. |
| 920 | if (!ResDef && SchedRead.TheDef->getName() != "ReadDefault") { |
Joerg Sonnenberger | 635debe | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 921 | PrintFatalError(ProcModel.ModelDef->getLoc(), |
Craig Topper | 01ebd9b | 2017-10-26 20:49:36 +0000 | [diff] [blame] | 922 | Twine("Processor does not define resources for ") + |
| 923 | SchedRead.TheDef->getName()); |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 924 | } |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 925 | return ResDef; |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 926 | } |
| 927 | |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 928 | // Expand an explicit list of processor resources into a full list of implied |
Andrew Trick | a3801a3 | 2013-04-23 23:45:16 +0000 | [diff] [blame] | 929 | // resource groups and super resources that cover them. |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 930 | void SubtargetEmitter::ExpandProcResources(RecVec &PRVec, |
| 931 | std::vector<int64_t> &Cycles, |
Andrew Trick | a3801a3 | 2013-04-23 23:45:16 +0000 | [diff] [blame] | 932 | const CodeGenProcModel &PM) { |
Clement Courbet | 5eeed77 | 2018-06-13 09:41:49 +0000 | [diff] [blame] | 933 | assert(PRVec.size() == Cycles.size() && "failed precondition"); |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 934 | for (unsigned i = 0, e = PRVec.size(); i != e; ++i) { |
Andrew Trick | a3801a3 | 2013-04-23 23:45:16 +0000 | [diff] [blame] | 935 | Record *PRDef = PRVec[i]; |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 936 | RecVec SubResources; |
Andrew Trick | a3801a3 | 2013-04-23 23:45:16 +0000 | [diff] [blame] | 937 | if (PRDef->isSubClassOf("ProcResGroup")) |
| 938 | SubResources = PRDef->getValueAsListOfDefs("Resources"); |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 939 | else { |
Andrew Trick | a3801a3 | 2013-04-23 23:45:16 +0000 | [diff] [blame] | 940 | SubResources.push_back(PRDef); |
Evandro Menezes | 9dc54e2 | 2017-11-21 21:33:52 +0000 | [diff] [blame] | 941 | PRDef = SchedModels.findProcResUnits(PRDef, PM, PRDef->getLoc()); |
Andrew Trick | a3801a3 | 2013-04-23 23:45:16 +0000 | [diff] [blame] | 942 | for (Record *SubDef = PRDef; |
| 943 | SubDef->getValueInit("Super")->isComplete();) { |
| 944 | if (SubDef->isSubClassOf("ProcResGroup")) { |
| 945 | // Disallow this for simplicitly. |
| 946 | PrintFatalError(SubDef->getLoc(), "Processor resource group " |
| 947 | " cannot be a super resources."); |
| 948 | } |
| 949 | Record *SuperDef = |
Evandro Menezes | 9dc54e2 | 2017-11-21 21:33:52 +0000 | [diff] [blame] | 950 | SchedModels.findProcResUnits(SubDef->getValueAsDef("Super"), PM, |
| 951 | SubDef->getLoc()); |
Andrew Trick | a3801a3 | 2013-04-23 23:45:16 +0000 | [diff] [blame] | 952 | PRVec.push_back(SuperDef); |
| 953 | Cycles.push_back(Cycles[i]); |
| 954 | SubDef = SuperDef; |
| 955 | } |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 956 | } |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 957 | for (Record *PR : PM.ProcResourceDefs) { |
| 958 | if (PR == PRDef || !PR->isSubClassOf("ProcResGroup")) |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 959 | continue; |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 960 | RecVec SuperResources = PR->getValueAsListOfDefs("Resources"); |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 961 | RecIter SubI = SubResources.begin(), SubE = SubResources.end(); |
Andrew Trick | 6aa7a87 | 2013-04-23 23:45:11 +0000 | [diff] [blame] | 962 | for( ; SubI != SubE; ++SubI) { |
David Majnemer | 0d955d0 | 2016-08-11 22:21:41 +0000 | [diff] [blame] | 963 | if (!is_contained(SuperResources, *SubI)) { |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 964 | break; |
Andrew Trick | 6aa7a87 | 2013-04-23 23:45:11 +0000 | [diff] [blame] | 965 | } |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 966 | } |
| 967 | if (SubI == SubE) { |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 968 | PRVec.push_back(PR); |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 969 | Cycles.push_back(Cycles[i]); |
| 970 | } |
| 971 | } |
| 972 | } |
| 973 | } |
| 974 | |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 975 | // Generate the SchedClass table for this processor and update global |
| 976 | // tables. Must be called for each processor in order. |
| 977 | void SubtargetEmitter::GenSchedClassTables(const CodeGenProcModel &ProcModel, |
| 978 | SchedClassTables &SchedTables) { |
| 979 | SchedTables.ProcSchedClasses.resize(SchedTables.ProcSchedClasses.size() + 1); |
| 980 | if (!ProcModel.hasInstrSchedModel()) |
| 981 | return; |
| 982 | |
| 983 | std::vector<MCSchedClassDesc> &SCTab = SchedTables.ProcSchedClasses.back(); |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 984 | LLVM_DEBUG(dbgs() << "\n+++ SCHED CLASSES (GenSchedClassTables) +++\n"); |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 985 | for (const CodeGenSchedClass &SC : SchedModels.schedClasses()) { |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 986 | LLVM_DEBUG(SC.dump(&SchedModels)); |
Andrew Trick | 7aba6be | 2012-10-03 23:06:25 +0000 | [diff] [blame] | 987 | |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 988 | SCTab.resize(SCTab.size() + 1); |
| 989 | MCSchedClassDesc &SCDesc = SCTab.back(); |
Andrew Trick | ab722bd | 2012-09-18 03:18:56 +0000 | [diff] [blame] | 990 | // SCDesc.Name is guarded by NDEBUG |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 991 | SCDesc.NumMicroOps = 0; |
| 992 | SCDesc.BeginGroup = false; |
| 993 | SCDesc.EndGroup = false; |
| 994 | SCDesc.WriteProcResIdx = 0; |
| 995 | SCDesc.WriteLatencyIdx = 0; |
| 996 | SCDesc.ReadAdvanceIdx = 0; |
| 997 | |
| 998 | // A Variant SchedClass has no resources of its own. |
Andrew Trick | e97978f | 2013-03-26 21:36:39 +0000 | [diff] [blame] | 999 | bool HasVariants = false; |
Javed Absar | 32e3cb7 | 2017-10-06 15:25:04 +0000 | [diff] [blame] | 1000 | for (const CodeGenSchedTransition &CGT : |
| 1001 | make_range(SC.Transitions.begin(), SC.Transitions.end())) { |
| 1002 | if (CGT.ProcIndices[0] == 0 || |
| 1003 | is_contained(CGT.ProcIndices, ProcModel.Index)) { |
Andrew Trick | e97978f | 2013-03-26 21:36:39 +0000 | [diff] [blame] | 1004 | HasVariants = true; |
| 1005 | break; |
| 1006 | } |
| 1007 | } |
| 1008 | if (HasVariants) { |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1009 | SCDesc.NumMicroOps = MCSchedClassDesc::VariantNumMicroOps; |
| 1010 | continue; |
| 1011 | } |
| 1012 | |
| 1013 | // Determine if the SchedClass is actually reachable on this processor. If |
| 1014 | // not don't try to locate the processor resources, it will fail. |
| 1015 | // If ProcIndices contains 0, this class applies to all processors. |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 1016 | assert(!SC.ProcIndices.empty() && "expect at least one procidx"); |
| 1017 | if (SC.ProcIndices[0] != 0) { |
David Majnemer | 4253126 | 2016-08-12 03:55:06 +0000 | [diff] [blame] | 1018 | if (!is_contained(SC.ProcIndices, ProcModel.Index)) |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1019 | continue; |
| 1020 | } |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 1021 | IdxVec Writes = SC.Writes; |
| 1022 | IdxVec Reads = SC.Reads; |
| 1023 | if (!SC.InstRWs.empty()) { |
Sylvestre Ledru | 543f15b | 2018-03-17 17:30:08 +0000 | [diff] [blame] | 1024 | // This class has a default ReadWrite list which can be overridden by |
Andrew Trick | 7aba6be | 2012-10-03 23:06:25 +0000 | [diff] [blame] | 1025 | // InstRW definitions. |
Craig Topper | 2406477 | 2014-04-15 07:20:03 +0000 | [diff] [blame] | 1026 | Record *RWDef = nullptr; |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 1027 | for (Record *RW : SC.InstRWs) { |
| 1028 | Record *RWModelDef = RW->getValueAsDef("SchedModel"); |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1029 | if (&ProcModel == &SchedModels.getProcModel(RWModelDef)) { |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 1030 | RWDef = RW; |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1031 | break; |
| 1032 | } |
| 1033 | } |
| 1034 | if (RWDef) { |
Andrew Trick | da984b1 | 2012-10-03 23:06:28 +0000 | [diff] [blame] | 1035 | Writes.clear(); |
| 1036 | Reads.clear(); |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1037 | SchedModels.findRWs(RWDef->getValueAsListOfDefs("OperandReadWrites"), |
| 1038 | Writes, Reads); |
| 1039 | } |
| 1040 | } |
Andrew Trick | bf8a28d | 2013-03-16 18:58:55 +0000 | [diff] [blame] | 1041 | if (Writes.empty()) { |
| 1042 | // Check this processor's itinerary class resources. |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 1043 | for (Record *I : ProcModel.ItinRWDefs) { |
| 1044 | RecVec Matched = I->getValueAsListOfDefs("MatchedItinClasses"); |
David Majnemer | 0d955d0 | 2016-08-11 22:21:41 +0000 | [diff] [blame] | 1045 | if (is_contained(Matched, SC.ItinClassDef)) { |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 1046 | SchedModels.findRWs(I->getValueAsListOfDefs("OperandReadWrites"), |
Andrew Trick | bf8a28d | 2013-03-16 18:58:55 +0000 | [diff] [blame] | 1047 | Writes, Reads); |
| 1048 | break; |
| 1049 | } |
| 1050 | } |
| 1051 | if (Writes.empty()) { |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 1052 | LLVM_DEBUG(dbgs() << ProcModel.ModelName |
| 1053 | << " does not have resources for class " << SC.Name |
| 1054 | << '\n'); |
Andrew Trick | bf8a28d | 2013-03-16 18:58:55 +0000 | [diff] [blame] | 1055 | } |
| 1056 | } |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1057 | // Sum resources across all operand writes. |
| 1058 | std::vector<MCWriteProcResEntry> WriteProcResources; |
| 1059 | std::vector<MCWriteLatencyEntry> WriteLatencies; |
Andrew Trick | cfe222c | 2012-09-19 04:43:19 +0000 | [diff] [blame] | 1060 | std::vector<std::string> WriterNames; |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1061 | std::vector<MCReadAdvanceEntry> ReadAdvanceEntries; |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 1062 | for (unsigned W : Writes) { |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1063 | IdxVec WriteSeq; |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 1064 | SchedModels.expandRWSeqForProc(W, WriteSeq, /*IsRead=*/false, |
Andrew Trick | da984b1 | 2012-10-03 23:06:28 +0000 | [diff] [blame] | 1065 | ProcModel); |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1066 | |
| 1067 | // For each operand, create a latency entry. |
| 1068 | MCWriteLatencyEntry WLEntry; |
| 1069 | WLEntry.Cycles = 0; |
Andrew Trick | cfe222c | 2012-09-19 04:43:19 +0000 | [diff] [blame] | 1070 | unsigned WriteID = WriteSeq.back(); |
| 1071 | WriterNames.push_back(SchedModels.getSchedWrite(WriteID).Name); |
| 1072 | // If this Write is not referenced by a ReadAdvance, don't distinguish it |
| 1073 | // from other WriteLatency entries. |
Andrew Trick | bf8a28d | 2013-03-16 18:58:55 +0000 | [diff] [blame] | 1074 | if (!SchedModels.hasReadOfWrite( |
| 1075 | SchedModels.getSchedWrite(WriteID).TheDef)) { |
Andrew Trick | cfe222c | 2012-09-19 04:43:19 +0000 | [diff] [blame] | 1076 | WriteID = 0; |
| 1077 | } |
| 1078 | WLEntry.WriteResourceID = WriteID; |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1079 | |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 1080 | for (unsigned WS : WriteSeq) { |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1081 | |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 1082 | Record *WriteRes = |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 1083 | FindWriteResources(SchedModels.getSchedWrite(WS), ProcModel); |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1084 | |
| 1085 | // Mark the parent class as invalid for unsupported write types. |
| 1086 | if (WriteRes->getValueAsBit("Unsupported")) { |
| 1087 | SCDesc.NumMicroOps = MCSchedClassDesc::InvalidNumMicroOps; |
| 1088 | break; |
| 1089 | } |
| 1090 | WLEntry.Cycles += WriteRes->getValueAsInt("Latency"); |
| 1091 | SCDesc.NumMicroOps += WriteRes->getValueAsInt("NumMicroOps"); |
| 1092 | SCDesc.BeginGroup |= WriteRes->getValueAsBit("BeginGroup"); |
| 1093 | SCDesc.EndGroup |= WriteRes->getValueAsBit("EndGroup"); |
Javed Absar | 3d59437 | 2017-03-27 20:46:37 +0000 | [diff] [blame] | 1094 | SCDesc.BeginGroup |= WriteRes->getValueAsBit("SingleIssue"); |
| 1095 | SCDesc.EndGroup |= WriteRes->getValueAsBit("SingleIssue"); |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1096 | |
| 1097 | // Create an entry for each ProcResource listed in WriteRes. |
| 1098 | RecVec PRVec = WriteRes->getValueAsListOfDefs("ProcResources"); |
| 1099 | std::vector<int64_t> Cycles = |
| 1100 | WriteRes->getValueAsListOfInts("ResourceCycles"); |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 1101 | |
Clement Courbet | 5eeed77 | 2018-06-13 09:41:49 +0000 | [diff] [blame] | 1102 | if (Cycles.empty()) { |
| 1103 | // If ResourceCycles is not provided, default to one cycle per |
| 1104 | // resource. |
| 1105 | Cycles.resize(PRVec.size(), 1); |
| 1106 | } else if (Cycles.size() != PRVec.size()) { |
| 1107 | // If ResourceCycles is provided, check consistency. |
| 1108 | PrintFatalError( |
| 1109 | WriteRes->getLoc(), |
| 1110 | Twine("Inconsistent resource cycles: !size(ResourceCycles) != " |
| 1111 | "!size(ProcResources): ") |
| 1112 | .concat(Twine(PRVec.size())) |
| 1113 | .concat(" vs ") |
| 1114 | .concat(Twine(Cycles.size()))); |
| 1115 | } |
| 1116 | |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 1117 | ExpandProcResources(PRVec, Cycles, ProcModel); |
| 1118 | |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1119 | for (unsigned PRIdx = 0, PREnd = PRVec.size(); |
| 1120 | PRIdx != PREnd; ++PRIdx) { |
| 1121 | MCWriteProcResEntry WPREntry; |
| 1122 | WPREntry.ProcResourceIdx = ProcModel.getProcResourceIdx(PRVec[PRIdx]); |
| 1123 | assert(WPREntry.ProcResourceIdx && "Bad ProcResourceIdx"); |
Andrew Trick | 4e67cba | 2013-03-14 21:21:50 +0000 | [diff] [blame] | 1124 | WPREntry.Cycles = Cycles[PRIdx]; |
Andrew Trick | 3821d9d | 2013-03-01 23:31:26 +0000 | [diff] [blame] | 1125 | // If this resource is already used in this sequence, add the current |
| 1126 | // entry's cycles so that the same resource appears to be used |
| 1127 | // serially, rather than multiple parallel uses. This is important for |
| 1128 | // in-order machine where the resource consumption is a hazard. |
| 1129 | unsigned WPRIdx = 0, WPREnd = WriteProcResources.size(); |
| 1130 | for( ; WPRIdx != WPREnd; ++WPRIdx) { |
| 1131 | if (WriteProcResources[WPRIdx].ProcResourceIdx |
| 1132 | == WPREntry.ProcResourceIdx) { |
| 1133 | WriteProcResources[WPRIdx].Cycles += WPREntry.Cycles; |
| 1134 | break; |
| 1135 | } |
| 1136 | } |
| 1137 | if (WPRIdx == WPREnd) |
| 1138 | WriteProcResources.push_back(WPREntry); |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1139 | } |
| 1140 | } |
| 1141 | WriteLatencies.push_back(WLEntry); |
| 1142 | } |
| 1143 | // Create an entry for each operand Read in this SchedClass. |
| 1144 | // Entries must be sorted first by UseIdx then by WriteResourceID. |
| 1145 | for (unsigned UseIdx = 0, EndIdx = Reads.size(); |
| 1146 | UseIdx != EndIdx; ++UseIdx) { |
Andrew Trick | 9257b8f | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 1147 | Record *ReadAdvance = |
| 1148 | FindReadAdvance(SchedModels.getSchedRead(Reads[UseIdx]), ProcModel); |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1149 | if (!ReadAdvance) |
| 1150 | continue; |
| 1151 | |
| 1152 | // Mark the parent class as invalid for unsupported write types. |
| 1153 | if (ReadAdvance->getValueAsBit("Unsupported")) { |
| 1154 | SCDesc.NumMicroOps = MCSchedClassDesc::InvalidNumMicroOps; |
| 1155 | break; |
| 1156 | } |
| 1157 | RecVec ValidWrites = ReadAdvance->getValueAsListOfDefs("ValidWrites"); |
| 1158 | IdxVec WriteIDs; |
| 1159 | if (ValidWrites.empty()) |
| 1160 | WriteIDs.push_back(0); |
| 1161 | else { |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 1162 | for (Record *VW : ValidWrites) { |
| 1163 | WriteIDs.push_back(SchedModels.getSchedRWIdx(VW, /*IsRead=*/false)); |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1164 | } |
| 1165 | } |
Fangrui Song | 0cac726 | 2018-09-27 02:13:45 +0000 | [diff] [blame] | 1166 | llvm::sort(WriteIDs); |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 1167 | for(unsigned W : WriteIDs) { |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1168 | MCReadAdvanceEntry RAEntry; |
| 1169 | RAEntry.UseIdx = UseIdx; |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 1170 | RAEntry.WriteResourceID = W; |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1171 | RAEntry.Cycles = ReadAdvance->getValueAsInt("Cycles"); |
| 1172 | ReadAdvanceEntries.push_back(RAEntry); |
| 1173 | } |
| 1174 | } |
| 1175 | if (SCDesc.NumMicroOps == MCSchedClassDesc::InvalidNumMicroOps) { |
| 1176 | WriteProcResources.clear(); |
| 1177 | WriteLatencies.clear(); |
| 1178 | ReadAdvanceEntries.clear(); |
| 1179 | } |
| 1180 | // Add the information for this SchedClass to the global tables using basic |
| 1181 | // compression. |
| 1182 | // |
| 1183 | // WritePrecRes entries are sorted by ProcResIdx. |
Fangrui Song | 0cac726 | 2018-09-27 02:13:45 +0000 | [diff] [blame] | 1184 | llvm::sort(WriteProcResources, LessWriteProcResources()); |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1185 | |
| 1186 | SCDesc.NumWriteProcResEntries = WriteProcResources.size(); |
| 1187 | std::vector<MCWriteProcResEntry>::iterator WPRPos = |
| 1188 | std::search(SchedTables.WriteProcResources.begin(), |
| 1189 | SchedTables.WriteProcResources.end(), |
| 1190 | WriteProcResources.begin(), WriteProcResources.end()); |
| 1191 | if (WPRPos != SchedTables.WriteProcResources.end()) |
| 1192 | SCDesc.WriteProcResIdx = WPRPos - SchedTables.WriteProcResources.begin(); |
| 1193 | else { |
| 1194 | SCDesc.WriteProcResIdx = SchedTables.WriteProcResources.size(); |
| 1195 | SchedTables.WriteProcResources.insert(WPRPos, WriteProcResources.begin(), |
| 1196 | WriteProcResources.end()); |
| 1197 | } |
| 1198 | // Latency entries must remain in operand order. |
| 1199 | SCDesc.NumWriteLatencyEntries = WriteLatencies.size(); |
| 1200 | std::vector<MCWriteLatencyEntry>::iterator WLPos = |
| 1201 | std::search(SchedTables.WriteLatencies.begin(), |
| 1202 | SchedTables.WriteLatencies.end(), |
| 1203 | WriteLatencies.begin(), WriteLatencies.end()); |
Andrew Trick | cfe222c | 2012-09-19 04:43:19 +0000 | [diff] [blame] | 1204 | if (WLPos != SchedTables.WriteLatencies.end()) { |
| 1205 | unsigned idx = WLPos - SchedTables.WriteLatencies.begin(); |
| 1206 | SCDesc.WriteLatencyIdx = idx; |
| 1207 | for (unsigned i = 0, e = WriteLatencies.size(); i < e; ++i) |
| 1208 | if (SchedTables.WriterNames[idx + i].find(WriterNames[i]) == |
| 1209 | std::string::npos) { |
| 1210 | SchedTables.WriterNames[idx + i] += std::string("_") + WriterNames[i]; |
| 1211 | } |
| 1212 | } |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1213 | else { |
| 1214 | SCDesc.WriteLatencyIdx = SchedTables.WriteLatencies.size(); |
Andrew Trick | cfe222c | 2012-09-19 04:43:19 +0000 | [diff] [blame] | 1215 | SchedTables.WriteLatencies.insert(SchedTables.WriteLatencies.end(), |
| 1216 | WriteLatencies.begin(), |
| 1217 | WriteLatencies.end()); |
| 1218 | SchedTables.WriterNames.insert(SchedTables.WriterNames.end(), |
| 1219 | WriterNames.begin(), WriterNames.end()); |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1220 | } |
| 1221 | // ReadAdvanceEntries must remain in operand order. |
| 1222 | SCDesc.NumReadAdvanceEntries = ReadAdvanceEntries.size(); |
| 1223 | std::vector<MCReadAdvanceEntry>::iterator RAPos = |
| 1224 | std::search(SchedTables.ReadAdvanceEntries.begin(), |
| 1225 | SchedTables.ReadAdvanceEntries.end(), |
| 1226 | ReadAdvanceEntries.begin(), ReadAdvanceEntries.end()); |
| 1227 | if (RAPos != SchedTables.ReadAdvanceEntries.end()) |
| 1228 | SCDesc.ReadAdvanceIdx = RAPos - SchedTables.ReadAdvanceEntries.begin(); |
| 1229 | else { |
| 1230 | SCDesc.ReadAdvanceIdx = SchedTables.ReadAdvanceEntries.size(); |
| 1231 | SchedTables.ReadAdvanceEntries.insert(RAPos, ReadAdvanceEntries.begin(), |
| 1232 | ReadAdvanceEntries.end()); |
| 1233 | } |
| 1234 | } |
| 1235 | } |
| 1236 | |
Andrew Trick | a72fca6 | 2012-09-17 22:18:50 +0000 | [diff] [blame] | 1237 | // Emit SchedClass tables for all processors and associated global tables. |
| 1238 | void SubtargetEmitter::EmitSchedClassTables(SchedClassTables &SchedTables, |
| 1239 | raw_ostream &OS) { |
| 1240 | // Emit global WriteProcResTable. |
| 1241 | OS << "\n// {ProcResourceIdx, Cycles}\n" |
| 1242 | << "extern const llvm::MCWriteProcResEntry " |
| 1243 | << Target << "WriteProcResTable[] = {\n" |
| 1244 | << " { 0, 0}, // Invalid\n"; |
| 1245 | for (unsigned WPRIdx = 1, WPREnd = SchedTables.WriteProcResources.size(); |
| 1246 | WPRIdx != WPREnd; ++WPRIdx) { |
| 1247 | MCWriteProcResEntry &WPREntry = SchedTables.WriteProcResources[WPRIdx]; |
| 1248 | OS << " {" << format("%2d", WPREntry.ProcResourceIdx) << ", " |
| 1249 | << format("%2d", WPREntry.Cycles) << "}"; |
| 1250 | if (WPRIdx + 1 < WPREnd) |
| 1251 | OS << ','; |
| 1252 | OS << " // #" << WPRIdx << '\n'; |
| 1253 | } |
| 1254 | OS << "}; // " << Target << "WriteProcResTable\n"; |
| 1255 | |
| 1256 | // Emit global WriteLatencyTable. |
| 1257 | OS << "\n// {Cycles, WriteResourceID}\n" |
| 1258 | << "extern const llvm::MCWriteLatencyEntry " |
| 1259 | << Target << "WriteLatencyTable[] = {\n" |
| 1260 | << " { 0, 0}, // Invalid\n"; |
| 1261 | for (unsigned WLIdx = 1, WLEnd = SchedTables.WriteLatencies.size(); |
| 1262 | WLIdx != WLEnd; ++WLIdx) { |
| 1263 | MCWriteLatencyEntry &WLEntry = SchedTables.WriteLatencies[WLIdx]; |
| 1264 | OS << " {" << format("%2d", WLEntry.Cycles) << ", " |
| 1265 | << format("%2d", WLEntry.WriteResourceID) << "}"; |
| 1266 | if (WLIdx + 1 < WLEnd) |
| 1267 | OS << ','; |
Andrew Trick | cfe222c | 2012-09-19 04:43:19 +0000 | [diff] [blame] | 1268 | OS << " // #" << WLIdx << " " << SchedTables.WriterNames[WLIdx] << '\n'; |
Andrew Trick | a72fca6 | 2012-09-17 22:18:50 +0000 | [diff] [blame] | 1269 | } |
| 1270 | OS << "}; // " << Target << "WriteLatencyTable\n"; |
| 1271 | |
| 1272 | // Emit global ReadAdvanceTable. |
| 1273 | OS << "\n// {UseIdx, WriteResourceID, Cycles}\n" |
| 1274 | << "extern const llvm::MCReadAdvanceEntry " |
| 1275 | << Target << "ReadAdvanceTable[] = {\n" |
| 1276 | << " {0, 0, 0}, // Invalid\n"; |
| 1277 | for (unsigned RAIdx = 1, RAEnd = SchedTables.ReadAdvanceEntries.size(); |
| 1278 | RAIdx != RAEnd; ++RAIdx) { |
| 1279 | MCReadAdvanceEntry &RAEntry = SchedTables.ReadAdvanceEntries[RAIdx]; |
| 1280 | OS << " {" << RAEntry.UseIdx << ", " |
| 1281 | << format("%2d", RAEntry.WriteResourceID) << ", " |
| 1282 | << format("%2d", RAEntry.Cycles) << "}"; |
| 1283 | if (RAIdx + 1 < RAEnd) |
| 1284 | OS << ','; |
| 1285 | OS << " // #" << RAIdx << '\n'; |
| 1286 | } |
| 1287 | OS << "}; // " << Target << "ReadAdvanceTable\n"; |
| 1288 | |
| 1289 | // Emit a SchedClass table for each processor. |
| 1290 | for (CodeGenSchedModels::ProcIter PI = SchedModels.procModelBegin(), |
| 1291 | PE = SchedModels.procModelEnd(); PI != PE; ++PI) { |
| 1292 | if (!PI->hasInstrSchedModel()) |
| 1293 | continue; |
| 1294 | |
| 1295 | std::vector<MCSchedClassDesc> &SCTab = |
Rafael Espindola | 7296139 | 2012-11-02 20:57:36 +0000 | [diff] [blame] | 1296 | SchedTables.ProcSchedClasses[1 + (PI - SchedModels.procModelBegin())]; |
Andrew Trick | a72fca6 | 2012-09-17 22:18:50 +0000 | [diff] [blame] | 1297 | |
| 1298 | OS << "\n// {Name, NumMicroOps, BeginGroup, EndGroup," |
| 1299 | << " WriteProcResIdx,#, WriteLatencyIdx,#, ReadAdvanceIdx,#}\n"; |
| 1300 | OS << "static const llvm::MCSchedClassDesc " |
| 1301 | << PI->ModelName << "SchedClasses[] = {\n"; |
| 1302 | |
| 1303 | // The first class is always invalid. We no way to distinguish it except by |
| 1304 | // name and position. |
Andrew Trick | bf8a28d | 2013-03-16 18:58:55 +0000 | [diff] [blame] | 1305 | assert(SchedModels.getSchedClass(0).Name == "NoInstrModel" |
Andrew Trick | a72fca6 | 2012-09-17 22:18:50 +0000 | [diff] [blame] | 1306 | && "invalid class not first"); |
| 1307 | OS << " {DBGFIELD(\"InvalidSchedClass\") " |
| 1308 | << MCSchedClassDesc::InvalidNumMicroOps |
Eugene Zelenko | 75259bb | 2016-05-17 17:04:23 +0000 | [diff] [blame] | 1309 | << ", false, false, 0, 0, 0, 0, 0, 0},\n"; |
Andrew Trick | a72fca6 | 2012-09-17 22:18:50 +0000 | [diff] [blame] | 1310 | |
| 1311 | for (unsigned SCIdx = 1, SCEnd = SCTab.size(); SCIdx != SCEnd; ++SCIdx) { |
| 1312 | MCSchedClassDesc &MCDesc = SCTab[SCIdx]; |
| 1313 | const CodeGenSchedClass &SchedClass = SchedModels.getSchedClass(SCIdx); |
| 1314 | OS << " {DBGFIELD(\"" << SchedClass.Name << "\") "; |
| 1315 | if (SchedClass.Name.size() < 18) |
| 1316 | OS.indent(18 - SchedClass.Name.size()); |
| 1317 | OS << MCDesc.NumMicroOps |
Eugene Zelenko | 75259bb | 2016-05-17 17:04:23 +0000 | [diff] [blame] | 1318 | << ", " << ( MCDesc.BeginGroup ? "true" : "false" ) |
| 1319 | << ", " << ( MCDesc.EndGroup ? "true" : "false" ) |
Andrew Trick | a72fca6 | 2012-09-17 22:18:50 +0000 | [diff] [blame] | 1320 | << ", " << format("%2d", MCDesc.WriteProcResIdx) |
| 1321 | << ", " << MCDesc.NumWriteProcResEntries |
| 1322 | << ", " << format("%2d", MCDesc.WriteLatencyIdx) |
| 1323 | << ", " << MCDesc.NumWriteLatencyEntries |
| 1324 | << ", " << format("%2d", MCDesc.ReadAdvanceIdx) |
Craig Topper | df1285b | 2017-10-24 15:50:53 +0000 | [diff] [blame] | 1325 | << ", " << MCDesc.NumReadAdvanceEntries |
| 1326 | << "}, // #" << SCIdx << '\n'; |
Andrew Trick | a72fca6 | 2012-09-17 22:18:50 +0000 | [diff] [blame] | 1327 | } |
| 1328 | OS << "}; // " << PI->ModelName << "SchedClasses\n"; |
| 1329 | } |
| 1330 | } |
| 1331 | |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 1332 | void SubtargetEmitter::EmitProcessorModels(raw_ostream &OS) { |
| 1333 | // For each processor model. |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 1334 | for (const CodeGenProcModel &PM : SchedModels.procModels()) { |
Andrea Di Biagio | 9da4d6d | 2018-04-03 13:36:24 +0000 | [diff] [blame] | 1335 | // Emit extra processor info if available. |
| 1336 | if (PM.hasExtraProcessorInfo()) |
| 1337 | EmitExtraProcessorInfo(PM, OS); |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 1338 | // Emit processor resource table. |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 1339 | if (PM.hasInstrSchedModel()) |
| 1340 | EmitProcessorResources(PM, OS); |
| 1341 | else if(!PM.ProcResourceDefs.empty()) |
| 1342 | PrintFatalError(PM.ModelDef->getLoc(), "SchedMachineModel defines " |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1343 | "ProcResources without defining WriteRes SchedWriteRes"); |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 1344 | |
Andrew Trick | 73d7736 | 2012-06-05 03:44:40 +0000 | [diff] [blame] | 1345 | // Begin processor itinerary properties |
| 1346 | OS << "\n"; |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 1347 | OS << "static const llvm::MCSchedModel " << PM.ModelName << " = {\n"; |
| 1348 | EmitProcessorProp(OS, PM.ModelDef, "IssueWidth", ','); |
| 1349 | EmitProcessorProp(OS, PM.ModelDef, "MicroOpBufferSize", ','); |
| 1350 | EmitProcessorProp(OS, PM.ModelDef, "LoopMicroOpBufferSize", ','); |
| 1351 | EmitProcessorProp(OS, PM.ModelDef, "LoadLatency", ','); |
| 1352 | EmitProcessorProp(OS, PM.ModelDef, "HighLatency", ','); |
| 1353 | EmitProcessorProp(OS, PM.ModelDef, "MispredictPenalty", ','); |
Andrew Trick | b6854d8 | 2013-09-25 18:14:12 +0000 | [diff] [blame] | 1354 | |
Eugene Zelenko | 75259bb | 2016-05-17 17:04:23 +0000 | [diff] [blame] | 1355 | bool PostRAScheduler = |
| 1356 | (PM.ModelDef ? PM.ModelDef->getValueAsBit("PostRAScheduler") : false); |
Sanjay Patel | a2f658d | 2014-07-15 22:39:58 +0000 | [diff] [blame] | 1357 | |
Eugene Zelenko | 75259bb | 2016-05-17 17:04:23 +0000 | [diff] [blame] | 1358 | OS << " " << (PostRAScheduler ? "true" : "false") << ", // " |
| 1359 | << "PostRAScheduler\n"; |
| 1360 | |
| 1361 | bool CompleteModel = |
| 1362 | (PM.ModelDef ? PM.ModelDef->getValueAsBit("CompleteModel") : false); |
| 1363 | |
| 1364 | OS << " " << (CompleteModel ? "true" : "false") << ", // " |
| 1365 | << "CompleteModel\n"; |
Andrew Trick | b6854d8 | 2013-09-25 18:14:12 +0000 | [diff] [blame] | 1366 | |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 1367 | OS << " " << PM.Index << ", // Processor ID\n"; |
| 1368 | if (PM.hasInstrSchedModel()) |
| 1369 | OS << " " << PM.ModelName << "ProcResources" << ",\n" |
| 1370 | << " " << PM.ModelName << "SchedClasses" << ",\n" |
| 1371 | << " " << PM.ProcResourceDefs.size()+1 << ",\n" |
Andrew Trick | ab722bd | 2012-09-18 03:18:56 +0000 | [diff] [blame] | 1372 | << " " << (SchedModels.schedClassEnd() |
| 1373 | - SchedModels.schedClassBegin()) << ",\n"; |
| 1374 | else |
Hans Wennborg | 083ca9b | 2015-10-06 23:24:35 +0000 | [diff] [blame] | 1375 | OS << " nullptr, nullptr, 0, 0," |
| 1376 | << " // No instruction-level machine model.\n"; |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 1377 | if (PM.hasItineraries()) |
Andrea Di Biagio | 9da4d6d | 2018-04-03 13:36:24 +0000 | [diff] [blame] | 1378 | OS << " " << PM.ItinsDef->getName() << ",\n"; |
Andrew Trick | 9c30267 | 2012-06-22 03:58:51 +0000 | [diff] [blame] | 1379 | else |
Andrea Di Biagio | 9da4d6d | 2018-04-03 13:36:24 +0000 | [diff] [blame] | 1380 | OS << " nullptr, // No Itinerary\n"; |
| 1381 | if (PM.hasExtraProcessorInfo()) |
Clement Courbet | b449379 | 2018-04-10 08:16:37 +0000 | [diff] [blame] | 1382 | OS << " &" << PM.ModelName << "ExtraInfo,\n"; |
Andrea Di Biagio | 9da4d6d | 2018-04-03 13:36:24 +0000 | [diff] [blame] | 1383 | else |
Clement Courbet | b449379 | 2018-04-10 08:16:37 +0000 | [diff] [blame] | 1384 | OS << " nullptr // No extra processor descriptor\n"; |
Craig Topper | 194cb74 | 2017-10-24 15:50:55 +0000 | [diff] [blame] | 1385 | OS << "};\n"; |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 1386 | } |
Jim Laskey | 3763a50 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | // |
Clement Courbet | 41c8af3 | 2018-10-25 07:44:01 +0000 | [diff] [blame] | 1390 | // EmitProcessorLookup - generate cpu name to sched model lookup tables. |
Jim Laskey | 3763a50 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 1391 | // |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 1392 | void SubtargetEmitter::EmitProcessorLookup(raw_ostream &OS) { |
Jim Laskey | 3763a50 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 1393 | // Gather and sort processor information |
| 1394 | std::vector<Record*> ProcessorList = |
| 1395 | Records.getAllDerivedDefinitions("Processor"); |
Fangrui Song | 0cac726 | 2018-09-27 02:13:45 +0000 | [diff] [blame] | 1396 | llvm::sort(ProcessorList, LessRecordFieldName()); |
Jim Laskey | 3763a50 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 1397 | |
Clement Courbet | 41c8af3 | 2018-10-25 07:44:01 +0000 | [diff] [blame] | 1398 | // Begin processor->sched model table |
Jim Laskey | 3763a50 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 1399 | OS << "\n"; |
Clement Courbet | 41c8af3 | 2018-10-25 07:44:01 +0000 | [diff] [blame] | 1400 | OS << "// Sorted (by key) array of sched model for CPU subtype.\n" |
| 1401 | << "extern const llvm::SubtargetInfoKV " << Target |
| 1402 | << "ProcSchedKV[] = {\n"; |
Jim Laskey | 3763a50 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 1403 | // For each processor |
Craig Topper | df1285b | 2017-10-24 15:50:53 +0000 | [diff] [blame] | 1404 | for (Record *Processor : ProcessorList) { |
Craig Topper | bcd3c37 | 2017-05-31 21:12:46 +0000 | [diff] [blame] | 1405 | StringRef Name = Processor->getValueAsString("Name"); |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 1406 | const std::string &ProcModelName = |
Andrew Trick | 7668649 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 1407 | SchedModels.getModelForProc(Processor).ModelName; |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 1408 | |
Jim Laskey | 3763a50 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 1409 | // Emit as { "cpu", procinit }, |
Craig Topper | df1285b | 2017-10-24 15:50:53 +0000 | [diff] [blame] | 1410 | OS << " { \"" << Name << "\", (const void *)&" << ProcModelName << " },\n"; |
Jim Laskey | 3763a50 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 1411 | } |
Clement Courbet | 41c8af3 | 2018-10-25 07:44:01 +0000 | [diff] [blame] | 1412 | // End processor->sched model table |
Jim Laskey | 3763a50 | 2005-10-31 17:16:01 +0000 | [diff] [blame] | 1413 | OS << "};\n"; |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | // |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 1417 | // EmitSchedModel - Emits all scheduling model tables, folding common patterns. |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 1418 | // |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 1419 | void SubtargetEmitter::EmitSchedModel(raw_ostream &OS) { |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 1420 | OS << "#ifdef DBGFIELD\n" |
| 1421 | << "#error \"<target>GenSubtargetInfo.inc requires a DBGFIELD macro\"\n" |
| 1422 | << "#endif\n" |
Aaron Ballman | 615eb47 | 2017-10-15 14:32:27 +0000 | [diff] [blame] | 1423 | << "#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)\n" |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 1424 | << "#define DBGFIELD(x) x,\n" |
| 1425 | << "#else\n" |
| 1426 | << "#define DBGFIELD(x)\n" |
| 1427 | << "#endif\n"; |
| 1428 | |
Andrew Trick | bf8a28d | 2013-03-16 18:58:55 +0000 | [diff] [blame] | 1429 | if (SchedModels.hasItineraries()) { |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 1430 | std::vector<std::vector<InstrItinerary>> ProcItinLists; |
Jim Laskey | 802748c | 2005-11-01 20:06:59 +0000 | [diff] [blame] | 1431 | // Emit the stage data |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 1432 | EmitStageAndOperandCycleData(OS, ProcItinLists); |
| 1433 | EmitItineraries(OS, ProcItinLists); |
Jim Laskey | 802748c | 2005-11-01 20:06:59 +0000 | [diff] [blame] | 1434 | } |
Andrew Trick | a72fca6 | 2012-09-17 22:18:50 +0000 | [diff] [blame] | 1435 | OS << "\n// ===============================================================\n" |
| 1436 | << "// Data tables for the new per-operand machine model.\n"; |
Andrew Trick | 23f3c65 | 2012-09-17 22:18:45 +0000 | [diff] [blame] | 1437 | |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1438 | SchedClassTables SchedTables; |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 1439 | for (const CodeGenProcModel &ProcModel : SchedModels.procModels()) { |
| 1440 | GenSchedClassTables(ProcModel, SchedTables); |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1441 | } |
Andrew Trick | a72fca6 | 2012-09-17 22:18:50 +0000 | [diff] [blame] | 1442 | EmitSchedClassTables(SchedTables, OS); |
| 1443 | |
| 1444 | // Emit the processor machine model |
| 1445 | EmitProcessorModels(OS); |
| 1446 | // Emit the processor lookup data |
| 1447 | EmitProcessorLookup(OS); |
Andrew Trick | 9ef0882 | 2012-09-17 22:18:48 +0000 | [diff] [blame] | 1448 | |
Craig Topper | 194cb74 | 2017-10-24 15:50:55 +0000 | [diff] [blame] | 1449 | OS << "\n#undef DBGFIELD"; |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 1450 | } |
| 1451 | |
Andrea Di Biagio | b31f918 | 2018-04-26 18:03:24 +0000 | [diff] [blame] | 1452 | static void emitPredicateProlog(const RecordKeeper &Records, raw_ostream &OS) { |
| 1453 | std::string Buffer; |
| 1454 | raw_string_ostream Stream(Buffer); |
| 1455 | |
| 1456 | // Collect all the PredicateProlog records and print them to the output |
| 1457 | // stream. |
| 1458 | std::vector<Record *> Prologs = |
| 1459 | Records.getAllDerivedDefinitions("PredicateProlog"); |
Fangrui Song | 0cac726 | 2018-09-27 02:13:45 +0000 | [diff] [blame] | 1460 | llvm::sort(Prologs, LessRecord()); |
Andrea Di Biagio | b31f918 | 2018-04-26 18:03:24 +0000 | [diff] [blame] | 1461 | for (Record *P : Prologs) |
| 1462 | Stream << P->getValueAsString("Code") << '\n'; |
| 1463 | |
| 1464 | Stream.flush(); |
| 1465 | OS << Buffer; |
| 1466 | } |
| 1467 | |
| 1468 | static void emitPredicates(const CodeGenSchedTransition &T, |
Andrea Di Biagio | 24d86d8 | 2018-08-13 11:09:04 +0000 | [diff] [blame] | 1469 | const CodeGenSchedClass &SC, PredicateExpander &PE, |
Andrea Di Biagio | b31f918 | 2018-04-26 18:03:24 +0000 | [diff] [blame] | 1470 | raw_ostream &OS) { |
Andrea Di Biagio | b31f918 | 2018-04-26 18:03:24 +0000 | [diff] [blame] | 1471 | std::string Buffer; |
Andrea Di Biagio | 2c6cbc8b | 2018-08-13 15:13:35 +0000 | [diff] [blame] | 1472 | raw_string_ostream SS(Buffer); |
Andrea Di Biagio | 24d86d8 | 2018-08-13 11:09:04 +0000 | [diff] [blame] | 1473 | |
| 1474 | auto IsTruePredicate = [](const Record *Rec) { |
| 1475 | return Rec->isSubClassOf("MCSchedPredicate") && |
| 1476 | Rec->getValueAsDef("Pred")->isSubClassOf("MCTrue"); |
| 1477 | }; |
| 1478 | |
| 1479 | // If not all predicates are MCTrue, then we need an if-stmt. |
| 1480 | unsigned NumNonTruePreds = |
| 1481 | T.PredTerm.size() - count_if(T.PredTerm, IsTruePredicate); |
Andrea Di Biagio | 2c6cbc8b | 2018-08-13 15:13:35 +0000 | [diff] [blame] | 1482 | |
| 1483 | SS.indent(PE.getIndentLevel() * 2); |
| 1484 | |
Andrea Di Biagio | 24d86d8 | 2018-08-13 11:09:04 +0000 | [diff] [blame] | 1485 | if (NumNonTruePreds) { |
| 1486 | bool FirstNonTruePredicate = true; |
Andrea Di Biagio | 2c6cbc8b | 2018-08-13 15:13:35 +0000 | [diff] [blame] | 1487 | SS << "if ("; |
| 1488 | |
| 1489 | PE.setIndentLevel(PE.getIndentLevel() + 2); |
| 1490 | |
Andrea Di Biagio | 24d86d8 | 2018-08-13 11:09:04 +0000 | [diff] [blame] | 1491 | for (const Record *Rec : T.PredTerm) { |
| 1492 | // Skip predicates that evaluate to "true". |
| 1493 | if (IsTruePredicate(Rec)) |
| 1494 | continue; |
| 1495 | |
| 1496 | if (FirstNonTruePredicate) { |
Andrea Di Biagio | 24d86d8 | 2018-08-13 11:09:04 +0000 | [diff] [blame] | 1497 | FirstNonTruePredicate = false; |
| 1498 | } else { |
Andrea Di Biagio | 2c6cbc8b | 2018-08-13 15:13:35 +0000 | [diff] [blame] | 1499 | SS << "\n"; |
| 1500 | SS.indent(PE.getIndentLevel() * 2); |
| 1501 | SS << "&& "; |
Andrea Di Biagio | 24d86d8 | 2018-08-13 11:09:04 +0000 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | if (Rec->isSubClassOf("MCSchedPredicate")) { |
Andrea Di Biagio | 2c6cbc8b | 2018-08-13 15:13:35 +0000 | [diff] [blame] | 1505 | PE.expandPredicate(SS, Rec->getValueAsDef("Pred")); |
Andrea Di Biagio | 24d86d8 | 2018-08-13 11:09:04 +0000 | [diff] [blame] | 1506 | continue; |
| 1507 | } |
| 1508 | |
| 1509 | // Expand this legacy predicate and wrap it around braces if there is more |
| 1510 | // than one predicate to expand. |
Andrea Di Biagio | 2c6cbc8b | 2018-08-13 15:13:35 +0000 | [diff] [blame] | 1511 | SS << ((NumNonTruePreds > 1) ? "(" : "") |
| 1512 | << Rec->getValueAsString("Predicate") |
| 1513 | << ((NumNonTruePreds > 1) ? ")" : ""); |
Andrea Di Biagio | 9514002 | 2018-05-25 15:55:37 +0000 | [diff] [blame] | 1514 | } |
Andrea Di Biagio | 24d86d8 | 2018-08-13 11:09:04 +0000 | [diff] [blame] | 1515 | |
Andrea Di Biagio | 2c6cbc8b | 2018-08-13 15:13:35 +0000 | [diff] [blame] | 1516 | SS << ")\n"; // end of if-stmt |
| 1517 | PE.decreaseIndentLevel(); |
| 1518 | SS.indent(PE.getIndentLevel() * 2); |
| 1519 | PE.decreaseIndentLevel(); |
Andrea Di Biagio | b31f918 | 2018-04-26 18:03:24 +0000 | [diff] [blame] | 1520 | } |
| 1521 | |
Andrea Di Biagio | 2c6cbc8b | 2018-08-13 15:13:35 +0000 | [diff] [blame] | 1522 | SS << "return " << T.ToClassIdx << "; // " << SC.Name << '\n'; |
| 1523 | SS.flush(); |
Andrea Di Biagio | b31f918 | 2018-04-26 18:03:24 +0000 | [diff] [blame] | 1524 | OS << Buffer; |
| 1525 | } |
| 1526 | |
Andrea Di Biagio | 8bdfd52 | 2018-08-10 10:43:43 +0000 | [diff] [blame] | 1527 | // Used by method `SubtargetEmitter::emitSchedModelHelpersImpl()` to generate |
| 1528 | // epilogue code for the auto-generated helper. |
| 1529 | void emitSchedModelHelperEpilogue(raw_ostream &OS, bool ShouldReturnZero) { |
| 1530 | if (ShouldReturnZero) { |
Andrea Di Biagio | 9514002 | 2018-05-25 15:55:37 +0000 | [diff] [blame] | 1531 | OS << " // Don't know how to resolve this scheduling class.\n" |
| 1532 | << " return 0;\n"; |
| 1533 | return; |
| 1534 | } |
| 1535 | |
| 1536 | OS << " report_fatal_error(\"Expected a variant SchedClass\");\n"; |
| 1537 | } |
| 1538 | |
Andrea Di Biagio | 8bdfd52 | 2018-08-10 10:43:43 +0000 | [diff] [blame] | 1539 | bool hasMCSchedPredicates(const CodeGenSchedTransition &T) { |
| 1540 | return all_of(T.PredTerm, [](const Record *Rec) { |
| 1541 | return Rec->isSubClassOf("MCSchedPredicate"); |
| 1542 | }); |
| 1543 | } |
| 1544 | |
| 1545 | void collectVariantClasses(const CodeGenSchedModels &SchedModels, |
| 1546 | IdxVec &VariantClasses, |
| 1547 | bool OnlyExpandMCInstPredicates) { |
| 1548 | for (const CodeGenSchedClass &SC : SchedModels.schedClasses()) { |
| 1549 | // Ignore non-variant scheduling classes. |
| 1550 | if (SC.Transitions.empty()) |
| 1551 | continue; |
| 1552 | |
| 1553 | if (OnlyExpandMCInstPredicates) { |
Evandro Menezes | 079bf4b | 2018-11-23 21:17:33 +0000 | [diff] [blame] | 1554 | // Ignore this variant scheduling class no transitions use any meaningful |
Andrea Di Biagio | 8bdfd52 | 2018-08-10 10:43:43 +0000 | [diff] [blame] | 1555 | // MCSchedPredicate definitions. |
Evandro Menezes | 079bf4b | 2018-11-23 21:17:33 +0000 | [diff] [blame] | 1556 | if (!any_of(SC.Transitions, [](const CodeGenSchedTransition &T) { |
Andrea Di Biagio | 8bdfd52 | 2018-08-10 10:43:43 +0000 | [diff] [blame] | 1557 | return hasMCSchedPredicates(T); |
| 1558 | })) |
| 1559 | continue; |
| 1560 | } |
| 1561 | |
| 1562 | VariantClasses.push_back(SC.Index); |
| 1563 | } |
| 1564 | } |
| 1565 | |
| 1566 | void collectProcessorIndices(const CodeGenSchedClass &SC, IdxVec &ProcIndices) { |
| 1567 | // A variant scheduling class may define transitions for multiple |
| 1568 | // processors. This function identifies wich processors are associated with |
| 1569 | // transition rules specified by variant class `SC`. |
| 1570 | for (const CodeGenSchedTransition &T : SC.Transitions) { |
| 1571 | IdxVec PI; |
| 1572 | std::set_union(T.ProcIndices.begin(), T.ProcIndices.end(), |
| 1573 | ProcIndices.begin(), ProcIndices.end(), |
| 1574 | std::back_inserter(PI)); |
| 1575 | ProcIndices.swap(PI); |
| 1576 | } |
| 1577 | } |
| 1578 | |
| 1579 | void SubtargetEmitter::emitSchedModelHelpersImpl( |
| 1580 | raw_ostream &OS, bool OnlyExpandMCInstPredicates) { |
| 1581 | IdxVec VariantClasses; |
| 1582 | collectVariantClasses(SchedModels, VariantClasses, |
| 1583 | OnlyExpandMCInstPredicates); |
| 1584 | |
| 1585 | if (VariantClasses.empty()) { |
| 1586 | emitSchedModelHelperEpilogue(OS, OnlyExpandMCInstPredicates); |
| 1587 | return; |
| 1588 | } |
| 1589 | |
| 1590 | // Construct a switch statement where the condition is a check on the |
| 1591 | // scheduling class identifier. There is a `case` for every variant class |
| 1592 | // defined by the processor models of this target. |
| 1593 | // Each `case` implements a number of rules to resolve (i.e. to transition from) |
| 1594 | // a variant scheduling class to another scheduling class. Rules are |
| 1595 | // described by instances of CodeGenSchedTransition. Note that transitions may |
| 1596 | // not be valid for all processors. |
| 1597 | OS << " switch (SchedClass) {\n"; |
| 1598 | for (unsigned VC : VariantClasses) { |
| 1599 | IdxVec ProcIndices; |
| 1600 | const CodeGenSchedClass &SC = SchedModels.getSchedClass(VC); |
| 1601 | collectProcessorIndices(SC, ProcIndices); |
| 1602 | |
| 1603 | OS << " case " << VC << ": // " << SC.Name << '\n'; |
| 1604 | |
Andrea Di Biagio | 9eaf5aa | 2018-08-14 18:36:54 +0000 | [diff] [blame] | 1605 | PredicateExpander PE(Target); |
Andrea Di Biagio | 8bdfd52 | 2018-08-10 10:43:43 +0000 | [diff] [blame] | 1606 | PE.setByRef(false); |
| 1607 | PE.setExpandForMC(OnlyExpandMCInstPredicates); |
| 1608 | for (unsigned PI : ProcIndices) { |
| 1609 | OS << " "; |
Evandro Menezes | 079bf4b | 2018-11-23 21:17:33 +0000 | [diff] [blame] | 1610 | |
Andrea Di Biagio | 8bdfd52 | 2018-08-10 10:43:43 +0000 | [diff] [blame] | 1611 | // Emit a guard on the processor ID. |
| 1612 | if (PI != 0) { |
| 1613 | OS << (OnlyExpandMCInstPredicates |
| 1614 | ? "if (CPUID == " |
| 1615 | : "if (SchedModel->getProcessorID() == "); |
| 1616 | OS << PI << ") "; |
| 1617 | OS << "{ // " << (SchedModels.procModelBegin() + PI)->ModelName << '\n'; |
| 1618 | } |
| 1619 | |
| 1620 | // Now emit transitions associated with processor PI. |
| 1621 | for (const CodeGenSchedTransition &T : SC.Transitions) { |
| 1622 | if (PI != 0 && !count(T.ProcIndices, PI)) |
| 1623 | continue; |
Evandro Menezes | 079bf4b | 2018-11-23 21:17:33 +0000 | [diff] [blame] | 1624 | |
| 1625 | // Emit only transitions based on MCSchedPredicate, if it's the case. |
| 1626 | // At least the transition specified by NoSchedPred is emitted, |
| 1627 | // which becomes the default transition for those variants otherwise |
| 1628 | // not based on MCSchedPredicate. |
| 1629 | // FIXME: preferably, llvm-mca should instead assume a reasonable |
| 1630 | // default when a variant transition is not based on MCSchedPredicate |
| 1631 | // for a given processor. |
| 1632 | if (OnlyExpandMCInstPredicates && !hasMCSchedPredicates(T)) |
| 1633 | continue; |
| 1634 | |
Andrea Di Biagio | 2c6cbc8b | 2018-08-13 15:13:35 +0000 | [diff] [blame] | 1635 | PE.setIndentLevel(3); |
Andrea Di Biagio | 8bdfd52 | 2018-08-10 10:43:43 +0000 | [diff] [blame] | 1636 | emitPredicates(T, SchedModels.getSchedClass(T.ToClassIdx), PE, OS); |
| 1637 | } |
| 1638 | |
| 1639 | OS << " }\n"; |
Evandro Menezes | 079bf4b | 2018-11-23 21:17:33 +0000 | [diff] [blame] | 1640 | |
Andrea Di Biagio | 8bdfd52 | 2018-08-10 10:43:43 +0000 | [diff] [blame] | 1641 | if (PI == 0) |
| 1642 | break; |
| 1643 | } |
| 1644 | |
| 1645 | if (SC.isInferred()) |
| 1646 | OS << " return " << SC.Index << ";\n"; |
| 1647 | OS << " break;\n"; |
| 1648 | } |
| 1649 | |
| 1650 | OS << " };\n"; |
| 1651 | |
| 1652 | emitSchedModelHelperEpilogue(OS, OnlyExpandMCInstPredicates); |
| 1653 | } |
| 1654 | |
Andrea Di Biagio | 9514002 | 2018-05-25 15:55:37 +0000 | [diff] [blame] | 1655 | void SubtargetEmitter::EmitSchedModelHelpers(const std::string &ClassName, |
| 1656 | raw_ostream &OS) { |
| 1657 | OS << "unsigned " << ClassName |
| 1658 | << "\n::resolveSchedClass(unsigned SchedClass, const MachineInstr *MI," |
| 1659 | << " const TargetSchedModel *SchedModel) const {\n"; |
| 1660 | |
| 1661 | // Emit the predicate prolog code. |
| 1662 | emitPredicateProlog(Records, OS); |
| 1663 | |
| 1664 | // Emit target predicates. |
| 1665 | emitSchedModelHelpersImpl(OS); |
Clement Courbet | 41c8af3 | 2018-10-25 07:44:01 +0000 | [diff] [blame] | 1666 | |
Andrea Di Biagio | be8616f | 2018-05-31 13:30:42 +0000 | [diff] [blame] | 1667 | OS << "} // " << ClassName << "::resolveSchedClass\n\n"; |
Andrea Di Biagio | 9514002 | 2018-05-25 15:55:37 +0000 | [diff] [blame] | 1668 | |
Andrea Di Biagio | be8616f | 2018-05-31 13:30:42 +0000 | [diff] [blame] | 1669 | OS << "unsigned " << ClassName |
| 1670 | << "\n::resolveVariantSchedClass(unsigned SchedClass, const MCInst *MI," |
| 1671 | << " unsigned CPUID) const {\n" |
| 1672 | << " return " << Target << "_MC" |
| 1673 | << "::resolveVariantSchedClassImpl(SchedClass, MI, CPUID);\n" |
Andrea Di Biagio | 8b6c314 | 2018-09-19 15:57:45 +0000 | [diff] [blame] | 1674 | << "} // " << ClassName << "::resolveVariantSchedClass\n\n"; |
| 1675 | |
| 1676 | STIPredicateExpander PE(Target); |
| 1677 | PE.setClassPrefix(ClassName); |
| 1678 | PE.setExpandDefinition(true); |
| 1679 | PE.setByRef(false); |
| 1680 | PE.setIndentLevel(0); |
| 1681 | |
| 1682 | for (const STIPredicateFunction &Fn : SchedModels.getSTIPredicates()) |
| 1683 | PE.expandSTIPredicate(OS, Fn); |
Andrew Trick | c6c8815 | 2012-09-18 03:41:43 +0000 | [diff] [blame] | 1684 | } |
| 1685 | |
Krzysztof Parzyszek | 788e768 | 2017-09-14 20:44:20 +0000 | [diff] [blame] | 1686 | void SubtargetEmitter::EmitHwModeCheck(const std::string &ClassName, |
| 1687 | raw_ostream &OS) { |
| 1688 | const CodeGenHwModes &CGH = TGT.getHwModes(); |
| 1689 | assert(CGH.getNumModeIds() > 0); |
| 1690 | if (CGH.getNumModeIds() == 1) |
| 1691 | return; |
| 1692 | |
| 1693 | OS << "unsigned " << ClassName << "::getHwMode() const {\n"; |
| 1694 | for (unsigned M = 1, NumModes = CGH.getNumModeIds(); M != NumModes; ++M) { |
| 1695 | const HwMode &HM = CGH.getMode(M); |
| 1696 | OS << " if (checkFeatures(\"" << HM.Features |
| 1697 | << "\")) return " << M << ";\n"; |
| 1698 | } |
| 1699 | OS << " return 0;\n}\n"; |
| 1700 | } |
| 1701 | |
Jim Laskey | 86f002c | 2005-10-27 19:47:21 +0000 | [diff] [blame] | 1702 | // |
Jim Laskey | a2b5235 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 1703 | // ParseFeaturesFunction - Produces a subtarget specific function for parsing |
| 1704 | // the subtarget features string. |
| 1705 | // |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1706 | void SubtargetEmitter::ParseFeaturesFunction(raw_ostream &OS, |
| 1707 | unsigned NumFeatures, |
| 1708 | unsigned NumProcs) { |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 1709 | std::vector<Record*> Features = |
| 1710 | Records.getAllDerivedDefinitions("SubtargetFeature"); |
Fangrui Song | 0cac726 | 2018-09-27 02:13:45 +0000 | [diff] [blame] | 1711 | llvm::sort(Features, LessRecord()); |
Jim Laskey | a2b5235 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 1712 | |
Andrew Trick | db6ed64 | 2011-04-01 01:56:55 +0000 | [diff] [blame] | 1713 | OS << "// ParseSubtargetFeatures - Parses features string setting specified\n" |
| 1714 | << "// subtarget options.\n" |
Evan Cheng | fe6e405 | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 1715 | << "void llvm::"; |
Jim Laskey | a2b5235 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 1716 | OS << Target; |
Evan Cheng | 1a72add6 | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 1717 | OS << "Subtarget::ParseSubtargetFeatures(StringRef CPU, StringRef FS) {\n" |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 1718 | << " LLVM_DEBUG(dbgs() << \"\\nFeatures:\" << FS);\n" |
| 1719 | << " LLVM_DEBUG(dbgs() << \"\\nCPU:\" << CPU << \"\\n\\n\");\n"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1720 | |
| 1721 | if (Features.empty()) { |
| 1722 | OS << "}\n"; |
| 1723 | return; |
| 1724 | } |
| 1725 | |
Andrew Trick | ba7b921 | 2012-09-18 05:33:15 +0000 | [diff] [blame] | 1726 | OS << " InitMCProcessorInfo(CPU, FS);\n" |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 1727 | << " const FeatureBitset& Bits = getFeatureBits();\n"; |
Bill Wendling | e618226 | 2007-05-04 20:38:40 +0000 | [diff] [blame] | 1728 | |
Craig Topper | 29c55dcb | 2016-02-13 06:03:32 +0000 | [diff] [blame] | 1729 | for (Record *R : Features) { |
Jim Laskey | dffe597 | 2005-10-28 21:47:29 +0000 | [diff] [blame] | 1730 | // Next record |
Craig Topper | bcd3c37 | 2017-05-31 21:12:46 +0000 | [diff] [blame] | 1731 | StringRef Instance = R->getName(); |
| 1732 | StringRef Value = R->getValueAsString("Value"); |
| 1733 | StringRef Attribute = R->getValueAsString("Attribute"); |
Evan Cheng | d98701c | 2006-01-27 08:09:42 +0000 | [diff] [blame] | 1734 | |
Dale Johannesen | 6ca3ccf | 2008-02-14 23:35:16 +0000 | [diff] [blame] | 1735 | if (Value=="true" || Value=="false") |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 1736 | OS << " if (Bits[" << Target << "::" |
| 1737 | << Instance << "]) " |
Dale Johannesen | 6ca3ccf | 2008-02-14 23:35:16 +0000 | [diff] [blame] | 1738 | << Attribute << " = " << Value << ";\n"; |
| 1739 | else |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 1740 | OS << " if (Bits[" << Target << "::" |
| 1741 | << Instance << "] && " |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1742 | << Attribute << " < " << Value << ") " |
| 1743 | << Attribute << " = " << Value << ";\n"; |
Jim Laskey | 802748c | 2005-11-01 20:06:59 +0000 | [diff] [blame] | 1744 | } |
Anton Korobeynikov | 08bf4c0 | 2009-05-23 19:50:50 +0000 | [diff] [blame] | 1745 | |
Evan Cheng | fe6e405 | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 1746 | OS << "}\n"; |
Jim Laskey | a2b5235 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 1747 | } |
| 1748 | |
Andrea Di Biagio | 8f66adec | 2018-05-25 16:02:43 +0000 | [diff] [blame] | 1749 | void SubtargetEmitter::emitGenMCSubtargetInfo(raw_ostream &OS) { |
Andrea Di Biagio | be8616f | 2018-05-31 13:30:42 +0000 | [diff] [blame] | 1750 | OS << "namespace " << Target << "_MC {\n" |
| 1751 | << "unsigned resolveVariantSchedClassImpl(unsigned SchedClass,\n" |
| 1752 | << " const MCInst *MI, unsigned CPUID) {\n"; |
| 1753 | emitSchedModelHelpersImpl(OS, /* OnlyExpandMCPredicates */ true); |
| 1754 | OS << "}\n"; |
| 1755 | OS << "} // end of namespace " << Target << "_MC\n\n"; |
| 1756 | |
Andrea Di Biagio | 8f66adec | 2018-05-25 16:02:43 +0000 | [diff] [blame] | 1757 | OS << "struct " << Target |
| 1758 | << "GenMCSubtargetInfo : public MCSubtargetInfo {\n"; |
| 1759 | OS << " " << Target << "GenMCSubtargetInfo(const Triple &TT, \n" |
| 1760 | << " StringRef CPU, StringRef FS, ArrayRef<SubtargetFeatureKV> PF,\n" |
Craig Topper | ca26808 | 2019-03-05 18:54:34 +0000 | [diff] [blame] | 1761 | << " ArrayRef<SubtargetSubTypeKV> PD,\n" |
Andrea Di Biagio | 8f66adec | 2018-05-25 16:02:43 +0000 | [diff] [blame] | 1762 | << " const SubtargetInfoKV *ProcSched,\n" |
| 1763 | << " const MCWriteProcResEntry *WPR,\n" |
| 1764 | << " const MCWriteLatencyEntry *WL,\n" |
| 1765 | << " const MCReadAdvanceEntry *RA, const InstrStage *IS,\n" |
| 1766 | << " const unsigned *OC, const unsigned *FP) :\n" |
| 1767 | << " MCSubtargetInfo(TT, CPU, FS, PF, PD, ProcSched,\n" |
| 1768 | << " WPR, WL, RA, IS, OC, FP) { }\n\n" |
| 1769 | << " unsigned resolveVariantSchedClass(unsigned SchedClass,\n" |
Andrea Di Biagio | be8616f | 2018-05-31 13:30:42 +0000 | [diff] [blame] | 1770 | << " const MCInst *MI, unsigned CPUID) const override {\n" |
| 1771 | << " return " << Target << "_MC" |
| 1772 | << "::resolveVariantSchedClassImpl(SchedClass, MI, CPUID); \n"; |
Andrea Di Biagio | 8f66adec | 2018-05-25 16:02:43 +0000 | [diff] [blame] | 1773 | OS << " }\n"; |
| 1774 | OS << "};\n"; |
| 1775 | } |
| 1776 | |
Andrea Di Biagio | 8b6c314 | 2018-09-19 15:57:45 +0000 | [diff] [blame] | 1777 | void SubtargetEmitter::EmitMCInstrAnalysisPredicateFunctions(raw_ostream &OS) { |
| 1778 | OS << "\n#ifdef GET_STIPREDICATE_DECLS_FOR_MC_ANALYSIS\n"; |
| 1779 | OS << "#undef GET_STIPREDICATE_DECLS_FOR_MC_ANALYSIS\n\n"; |
| 1780 | |
| 1781 | STIPredicateExpander PE(Target); |
| 1782 | PE.setExpandForMC(true); |
| 1783 | PE.setByRef(true); |
| 1784 | for (const STIPredicateFunction &Fn : SchedModels.getSTIPredicates()) |
| 1785 | PE.expandSTIPredicate(OS, Fn); |
| 1786 | |
| 1787 | OS << "#endif // GET_STIPREDICATE_DECLS_FOR_MC_ANALYSIS\n\n"; |
| 1788 | |
| 1789 | OS << "\n#ifdef GET_STIPREDICATE_DEFS_FOR_MC_ANALYSIS\n"; |
| 1790 | OS << "#undef GET_STIPREDICATE_DEFS_FOR_MC_ANALYSIS\n\n"; |
| 1791 | |
| 1792 | std::string ClassPrefix = Target + "MCInstrAnalysis"; |
| 1793 | PE.setExpandDefinition(true); |
| 1794 | PE.setClassPrefix(ClassPrefix); |
| 1795 | PE.setIndentLevel(0); |
| 1796 | for (const STIPredicateFunction &Fn : SchedModels.getSTIPredicates()) |
| 1797 | PE.expandSTIPredicate(OS, Fn); |
| 1798 | |
| 1799 | OS << "#endif // GET_STIPREDICATE_DEFS_FOR_MC_ANALYSIS\n\n"; |
| 1800 | } |
| 1801 | |
Anton Korobeynikov | 08bf4c0 | 2009-05-23 19:50:50 +0000 | [diff] [blame] | 1802 | // |
Jim Laskey | cfda85a | 2005-10-21 19:00:04 +0000 | [diff] [blame] | 1803 | // SubtargetEmitter::run - Main subtarget enumeration emitter. |
| 1804 | // |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 1805 | void SubtargetEmitter::run(raw_ostream &OS) { |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 1806 | emitSourceFileHeader("Subtarget Enumeration Source Fragment", OS); |
Jim Laskey | cfda85a | 2005-10-21 19:00:04 +0000 | [diff] [blame] | 1807 | |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 1808 | OS << "\n#ifdef GET_SUBTARGETINFO_ENUM\n"; |
Eugene Zelenko | 75259bb | 2016-05-17 17:04:23 +0000 | [diff] [blame] | 1809 | OS << "#undef GET_SUBTARGETINFO_ENUM\n\n"; |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 1810 | |
Craig Topper | 4f61308 | 2019-03-01 02:19:26 +0000 | [diff] [blame] | 1811 | DenseMap<Record *, unsigned> FeatureMap; |
| 1812 | |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 1813 | OS << "namespace llvm {\n"; |
Craig Topper | 4f61308 | 2019-03-01 02:19:26 +0000 | [diff] [blame] | 1814 | Enumeration(OS, FeatureMap); |
Eugene Zelenko | 75259bb | 2016-05-17 17:04:23 +0000 | [diff] [blame] | 1815 | OS << "} // end namespace llvm\n\n"; |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 1816 | OS << "#endif // GET_SUBTARGETINFO_ENUM\n\n"; |
| 1817 | |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1818 | OS << "\n#ifdef GET_SUBTARGETINFO_MC_DESC\n"; |
Eugene Zelenko | 75259bb | 2016-05-17 17:04:23 +0000 | [diff] [blame] | 1819 | OS << "#undef GET_SUBTARGETINFO_MC_DESC\n\n"; |
Anton Korobeynikov | 7d62e33 | 2010-04-18 20:31:01 +0000 | [diff] [blame] | 1820 | |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1821 | OS << "namespace llvm {\n"; |
Evan Cheng | bc153d4 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 1822 | #if 0 |
| 1823 | OS << "namespace {\n"; |
| 1824 | #endif |
Craig Topper | 4f61308 | 2019-03-01 02:19:26 +0000 | [diff] [blame] | 1825 | unsigned NumFeatures = FeatureKeyValues(OS, FeatureMap); |
Evan Cheng | bc153d4 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 1826 | OS << "\n"; |
Craig Topper | 4f61308 | 2019-03-01 02:19:26 +0000 | [diff] [blame] | 1827 | unsigned NumProcs = CPUKeyValues(OS, FeatureMap); |
Evan Cheng | bc153d4 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 1828 | OS << "\n"; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 1829 | EmitSchedModel(OS); |
Evan Cheng | bc153d4 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 1830 | OS << "\n"; |
| 1831 | #if 0 |
Eugene Zelenko | 75259bb | 2016-05-17 17:04:23 +0000 | [diff] [blame] | 1832 | OS << "} // end anonymous namespace\n\n"; |
Evan Cheng | bc153d4 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 1833 | #endif |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1834 | |
| 1835 | // MCInstrInfo initialization routine. |
Andrea Di Biagio | 8f66adec | 2018-05-25 16:02:43 +0000 | [diff] [blame] | 1836 | emitGenMCSubtargetInfo(OS); |
| 1837 | |
Craig Topper | 194cb74 | 2017-10-24 15:50:55 +0000 | [diff] [blame] | 1838 | OS << "\nstatic inline MCSubtargetInfo *create" << Target |
Duncan P. N. Exon Smith | 754e21f | 2015-07-10 22:43:42 +0000 | [diff] [blame] | 1839 | << "MCSubtargetInfoImpl(" |
Daniel Sanders | 50f1723 | 2015-09-15 16:17:27 +0000 | [diff] [blame] | 1840 | << "const Triple &TT, StringRef CPU, StringRef FS) {\n"; |
Andrea Di Biagio | 8f66adec | 2018-05-25 16:02:43 +0000 | [diff] [blame] | 1841 | OS << " return new " << Target << "GenMCSubtargetInfo(TT, CPU, FS, "; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1842 | if (NumFeatures) |
| 1843 | OS << Target << "FeatureKV, "; |
| 1844 | else |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 1845 | OS << "None, "; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1846 | if (NumProcs) |
| 1847 | OS << Target << "SubTypeKV, "; |
| 1848 | else |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 1849 | OS << "None, "; |
Andrew Trick | a72fca6 | 2012-09-17 22:18:50 +0000 | [diff] [blame] | 1850 | OS << '\n'; OS.indent(22); |
Andrew Trick | ab722bd | 2012-09-18 03:18:56 +0000 | [diff] [blame] | 1851 | OS << Target << "ProcSchedKV, " |
| 1852 | << Target << "WriteProcResTable, " |
| 1853 | << Target << "WriteLatencyTable, " |
| 1854 | << Target << "ReadAdvanceTable, "; |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 1855 | OS << '\n'; OS.indent(22); |
Andrew Trick | bf8a28d | 2013-03-16 18:58:55 +0000 | [diff] [blame] | 1856 | if (SchedModels.hasItineraries()) { |
Andrew Trick | ab722bd | 2012-09-18 03:18:56 +0000 | [diff] [blame] | 1857 | OS << Target << "Stages, " |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1858 | << Target << "OperandCycles, " |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 1859 | << Target << "ForwardingPaths"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1860 | } else |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 1861 | OS << "nullptr, nullptr, nullptr"; |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 1862 | OS << ");\n}\n\n"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1863 | |
Eugene Zelenko | 75259bb | 2016-05-17 17:04:23 +0000 | [diff] [blame] | 1864 | OS << "} // end namespace llvm\n\n"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1865 | |
| 1866 | OS << "#endif // GET_SUBTARGETINFO_MC_DESC\n\n"; |
| 1867 | |
| 1868 | OS << "\n#ifdef GET_SUBTARGETINFO_TARGET_DESC\n"; |
Eugene Zelenko | 75259bb | 2016-05-17 17:04:23 +0000 | [diff] [blame] | 1869 | OS << "#undef GET_SUBTARGETINFO_TARGET_DESC\n\n"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1870 | |
| 1871 | OS << "#include \"llvm/Support/Debug.h\"\n"; |
Eugene Zelenko | 75259bb | 2016-05-17 17:04:23 +0000 | [diff] [blame] | 1872 | OS << "#include \"llvm/Support/raw_ostream.h\"\n\n"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1873 | ParseFeaturesFunction(OS, NumFeatures, NumProcs); |
| 1874 | |
| 1875 | OS << "#endif // GET_SUBTARGETINFO_TARGET_DESC\n\n"; |
| 1876 | |
Evan Cheng | 0d639a2 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 1877 | // Create a TargetSubtargetInfo subclass to hide the MC layer initialization. |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1878 | OS << "\n#ifdef GET_SUBTARGETINFO_HEADER\n"; |
Eugene Zelenko | 75259bb | 2016-05-17 17:04:23 +0000 | [diff] [blame] | 1879 | OS << "#undef GET_SUBTARGETINFO_HEADER\n\n"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1880 | |
| 1881 | std::string ClassName = Target + "GenSubtargetInfo"; |
| 1882 | OS << "namespace llvm {\n"; |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 1883 | OS << "class DFAPacketizer;\n"; |
Andrea Di Biagio | be8616f | 2018-05-31 13:30:42 +0000 | [diff] [blame] | 1884 | OS << "namespace " << Target << "_MC {\n" |
| 1885 | << "unsigned resolveVariantSchedClassImpl(unsigned SchedClass," |
| 1886 | << " const MCInst *MI, unsigned CPUID);\n" |
| 1887 | << "}\n\n"; |
Evan Cheng | 0d639a2 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 1888 | OS << "struct " << ClassName << " : public TargetSubtargetInfo {\n" |
Daniel Sanders | 50f1723 | 2015-09-15 16:17:27 +0000 | [diff] [blame] | 1889 | << " explicit " << ClassName << "(const Triple &TT, StringRef CPU, " |
Evan Cheng | 1a72add6 | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 1890 | << "StringRef FS);\n" |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 1891 | << "public:\n" |
Daniel Sanders | a73f1fd | 2015-06-10 12:11:26 +0000 | [diff] [blame] | 1892 | << " unsigned resolveSchedClass(unsigned SchedClass, " |
| 1893 | << " const MachineInstr *DefMI," |
Craig Topper | 2d9361e | 2014-03-09 07:44:38 +0000 | [diff] [blame] | 1894 | << " const TargetSchedModel *SchedModel) const override;\n" |
Andrea Di Biagio | be8616f | 2018-05-31 13:30:42 +0000 | [diff] [blame] | 1895 | << " unsigned resolveVariantSchedClass(unsigned SchedClass," |
| 1896 | << " const MCInst *MI, unsigned CPUID) const override;\n" |
Sebastian Pop | ac35a4d | 2011-12-06 17:34:16 +0000 | [diff] [blame] | 1897 | << " DFAPacketizer *createDFAPacketizer(const InstrItineraryData *IID)" |
Krzysztof Parzyszek | 788e768 | 2017-09-14 20:44:20 +0000 | [diff] [blame] | 1898 | << " const;\n"; |
| 1899 | if (TGT.getHwModes().getNumModeIds() > 1) |
| 1900 | OS << " unsigned getHwMode() const override;\n"; |
Andrea Di Biagio | 8b6c314 | 2018-09-19 15:57:45 +0000 | [diff] [blame] | 1901 | |
| 1902 | STIPredicateExpander PE(Target); |
| 1903 | PE.setByRef(false); |
| 1904 | for (const STIPredicateFunction &Fn : SchedModels.getSTIPredicates()) |
| 1905 | PE.expandSTIPredicate(OS, Fn); |
| 1906 | |
Krzysztof Parzyszek | 788e768 | 2017-09-14 20:44:20 +0000 | [diff] [blame] | 1907 | OS << "};\n" |
| 1908 | << "} // end namespace llvm\n\n"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1909 | |
| 1910 | OS << "#endif // GET_SUBTARGETINFO_HEADER\n\n"; |
| 1911 | |
| 1912 | OS << "\n#ifdef GET_SUBTARGETINFO_CTOR\n"; |
Eugene Zelenko | 75259bb | 2016-05-17 17:04:23 +0000 | [diff] [blame] | 1913 | OS << "#undef GET_SUBTARGETINFO_CTOR\n\n"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1914 | |
Eugene Zelenko | 75259bb | 2016-05-17 17:04:23 +0000 | [diff] [blame] | 1915 | OS << "#include \"llvm/CodeGen/TargetSchedule.h\"\n\n"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1916 | OS << "namespace llvm {\n"; |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 1917 | OS << "extern const llvm::SubtargetFeatureKV " << Target << "FeatureKV[];\n"; |
Craig Topper | ca26808 | 2019-03-05 18:54:34 +0000 | [diff] [blame] | 1918 | OS << "extern const llvm::SubtargetSubTypeKV " << Target << "SubTypeKV[];\n"; |
Andrew Trick | a72fca6 | 2012-09-17 22:18:50 +0000 | [diff] [blame] | 1919 | OS << "extern const llvm::SubtargetInfoKV " << Target << "ProcSchedKV[];\n"; |
| 1920 | OS << "extern const llvm::MCWriteProcResEntry " |
| 1921 | << Target << "WriteProcResTable[];\n"; |
| 1922 | OS << "extern const llvm::MCWriteLatencyEntry " |
| 1923 | << Target << "WriteLatencyTable[];\n"; |
| 1924 | OS << "extern const llvm::MCReadAdvanceEntry " |
| 1925 | << Target << "ReadAdvanceTable[];\n"; |
| 1926 | |
Andrew Trick | bf8a28d | 2013-03-16 18:58:55 +0000 | [diff] [blame] | 1927 | if (SchedModels.hasItineraries()) { |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 1928 | OS << "extern const llvm::InstrStage " << Target << "Stages[];\n"; |
| 1929 | OS << "extern const unsigned " << Target << "OperandCycles[];\n"; |
Andrew Trick | 030e2f8 | 2012-07-07 03:59:48 +0000 | [diff] [blame] | 1930 | OS << "extern const unsigned " << Target << "ForwardingPaths[];\n"; |
Evan Cheng | bc153d4 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 1931 | } |
| 1932 | |
Daniel Sanders | 50f1723 | 2015-09-15 16:17:27 +0000 | [diff] [blame] | 1933 | OS << ClassName << "::" << ClassName << "(const Triple &TT, StringRef CPU, " |
| 1934 | << "StringRef FS)\n" |
Duncan P. N. Exon Smith | 754e21f | 2015-07-10 22:43:42 +0000 | [diff] [blame] | 1935 | << " : TargetSubtargetInfo(TT, CPU, FS, "; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1936 | if (NumFeatures) |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 1937 | OS << "makeArrayRef(" << Target << "FeatureKV, " << NumFeatures << "), "; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1938 | else |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 1939 | OS << "None, "; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1940 | if (NumProcs) |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 1941 | OS << "makeArrayRef(" << Target << "SubTypeKV, " << NumProcs << "), "; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1942 | else |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 1943 | OS << "None, "; |
Duncan P. N. Exon Smith | 754e21f | 2015-07-10 22:43:42 +0000 | [diff] [blame] | 1944 | OS << '\n'; OS.indent(24); |
Andrew Trick | ab722bd | 2012-09-18 03:18:56 +0000 | [diff] [blame] | 1945 | OS << Target << "ProcSchedKV, " |
| 1946 | << Target << "WriteProcResTable, " |
| 1947 | << Target << "WriteLatencyTable, " |
| 1948 | << Target << "ReadAdvanceTable, "; |
Duncan P. N. Exon Smith | 754e21f | 2015-07-10 22:43:42 +0000 | [diff] [blame] | 1949 | OS << '\n'; OS.indent(24); |
Andrew Trick | bf8a28d | 2013-03-16 18:58:55 +0000 | [diff] [blame] | 1950 | if (SchedModels.hasItineraries()) { |
Andrew Trick | ab722bd | 2012-09-18 03:18:56 +0000 | [diff] [blame] | 1951 | OS << Target << "Stages, " |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1952 | << Target << "OperandCycles, " |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 1953 | << Target << "ForwardingPaths"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1954 | } else |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 1955 | OS << "nullptr, nullptr, nullptr"; |
Duncan P. N. Exon Smith | 754e21f | 2015-07-10 22:43:42 +0000 | [diff] [blame] | 1956 | OS << ") {}\n\n"; |
Andrew Trick | a72fca6 | 2012-09-17 22:18:50 +0000 | [diff] [blame] | 1957 | |
Andrew Trick | c6c8815 | 2012-09-18 03:41:43 +0000 | [diff] [blame] | 1958 | EmitSchedModelHelpers(ClassName, OS); |
Krzysztof Parzyszek | 788e768 | 2017-09-14 20:44:20 +0000 | [diff] [blame] | 1959 | EmitHwModeCheck(ClassName, OS); |
Andrew Trick | c6c8815 | 2012-09-18 03:41:43 +0000 | [diff] [blame] | 1960 | |
Eugene Zelenko | 75259bb | 2016-05-17 17:04:23 +0000 | [diff] [blame] | 1961 | OS << "} // end namespace llvm\n\n"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 1962 | |
| 1963 | OS << "#endif // GET_SUBTARGETINFO_CTOR\n\n"; |
Andrea Di Biagio | 8b6c314 | 2018-09-19 15:57:45 +0000 | [diff] [blame] | 1964 | |
| 1965 | EmitMCInstrAnalysisPredicateFunctions(OS); |
Jim Laskey | cfda85a | 2005-10-21 19:00:04 +0000 | [diff] [blame] | 1966 | } |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 1967 | |
| 1968 | namespace llvm { |
| 1969 | |
| 1970 | void EmitSubtarget(RecordKeeper &RK, raw_ostream &OS) { |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 1971 | CodeGenTarget CGTarget(RK); |
| 1972 | SubtargetEmitter(RK, CGTarget).run(OS); |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 1973 | } |
| 1974 | |
Eugene Zelenko | 75259bb | 2016-05-17 17:04:23 +0000 | [diff] [blame] | 1975 | } // end namespace llvm |