blob: b4100fc36b5a7acd2720396362ce85c5afaa9560 [file] [log] [blame]
Eugene Zelenko6ac3f732016-01-26 18:48:36 +00001//===- DFAPacketizerEmitter.cpp - Packetization DFA for a VLIW machine ----===//
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This class parses the Schedule.td file and produces an API that can be used
10// to reason about whether an instruction can be added to a packet on a VLIW
11// architecture. The class internally generates a deterministic finite
12// automaton (DFA) that models all possible mappings of machine instructions
13// to functional units as instructions are added to a packet.
14//
15//===----------------------------------------------------------------------===//
16
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +000017#define DEBUG_TYPE "dfa-emitter"
18
jmolloy39525a62019-11-04 19:25:13 +000019#include "CodeGenSchedule.h"
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +000020#include "CodeGenTarget.h"
James Molloy12092a92019-10-17 08:34:29 +000021#include "DFAEmitter.h"
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +000022#include "llvm/ADT/DenseSet.h"
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +000023#include "llvm/ADT/SmallVector.h"
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +000024#include "llvm/ADT/StringExtras.h"
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +000025#include "llvm/Support/Debug.h"
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +000026#include "llvm/Support/raw_ostream.h"
jmolloy39525a62019-11-04 19:25:13 +000027#include "llvm/TableGen/Record.h"
28#include "llvm/TableGen/TableGenBackend.h"
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +000029#include <cassert>
30#include <cstdint>
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +000031#include <map>
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +000032#include <set>
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +000033#include <string>
James Molloy6ccd6732019-08-30 19:50:49 +000034#include <unordered_map>
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +000035#include <vector>
Eugene Zelenko6ac3f732016-01-26 18:48:36 +000036
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +000037using namespace llvm;
38
jmolloy39525a62019-11-04 19:25:13 +000039// We use a uint64_t to represent a resource bitmask.
40#define DFA_MAX_RESOURCES 64
Krzysztof Parzyszek6753f332015-11-22 15:20:19 +000041
42namespace {
jmolloy39525a62019-11-04 19:25:13 +000043using ResourceVector = SmallVector<uint64_t, 4>;
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +000044
jmolloy39525a62019-11-04 19:25:13 +000045struct ScheduleClass {
46 /// The parent itinerary index (processor model ID).
47 unsigned ItineraryID;
Krzysztof Parzyszek6753f332015-11-22 15:20:19 +000048
jmolloy39525a62019-11-04 19:25:13 +000049 /// Index within this itinerary of the schedule class.
50 unsigned Idx;
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +000051
jmolloy39525a62019-11-04 19:25:13 +000052 /// The index within the uniqued set of required resources of Resources.
53 unsigned ResourcesIdx;
Eugene Zelenko6ac3f732016-01-26 18:48:36 +000054
jmolloy39525a62019-11-04 19:25:13 +000055 /// Conjunctive list of resource requirements:
56 /// {a|b, b|c} => (a OR b) AND (b or c).
57 /// Resources are unique across all itineraries.
58 ResourceVector Resources;
59};
Krzysztof Parzyszek6753f332015-11-22 15:20:19 +000060
jmolloy39525a62019-11-04 19:25:13 +000061// Generates and prints out the DFA for resource tracking.
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +000062class DFAPacketizerEmitter {
63private:
64 std::string TargetName;
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +000065 RecordKeeper &Records;
66
jmolloy39525a62019-11-04 19:25:13 +000067 UniqueVector<ResourceVector> UniqueResources;
68 std::vector<ScheduleClass> ScheduleClasses;
69 std::map<std::string, uint64_t> FUNameToBitsMap;
70 std::map<unsigned, uint64_t> ComboBitToBitsMap;
71
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +000072public:
73 DFAPacketizerEmitter(RecordKeeper &R);
74
jmolloy39525a62019-11-04 19:25:13 +000075 // Construct a map of function unit names to bits.
76 int collectAllFuncUnits(
77 ArrayRef<const CodeGenProcModel *> ProcModels);
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +000078
jmolloy39525a62019-11-04 19:25:13 +000079 // Construct a map from a combo function unit bit to the bits of all included
80 // functional units.
81 int collectAllComboFuncs(ArrayRef<Record *> ComboFuncList);
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +000082
jmolloy39525a62019-11-04 19:25:13 +000083 ResourceVector getResourcesForItinerary(Record *Itinerary);
84 void createScheduleClasses(unsigned ItineraryIdx, const RecVec &Itineraries);
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +000085
James Molloy6ccd6732019-08-30 19:50:49 +000086 // Emit code for a subset of itineraries.
87 void emitForItineraries(raw_ostream &OS,
jmolloy39525a62019-11-04 19:25:13 +000088 std::vector<const CodeGenProcModel *> &ProcItinList,
James Molloy6ccd6732019-08-30 19:50:49 +000089 std::string DFAName);
90
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +000091 void run(raw_ostream &OS);
92};
Eugene Zelenko6ac3f732016-01-26 18:48:36 +000093} // end anonymous namespace
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +000094
jmolloy39525a62019-11-04 19:25:13 +000095DFAPacketizerEmitter::DFAPacketizerEmitter(RecordKeeper &R)
Benjamin Krameradcd0262020-01-28 20:23:46 +010096 : TargetName(std::string(CodeGenTarget(R).getName())), Records(R) {}
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +000097
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +000098int DFAPacketizerEmitter::collectAllFuncUnits(
jmolloy39525a62019-11-04 19:25:13 +000099 ArrayRef<const CodeGenProcModel *> ProcModels) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000100 LLVM_DEBUG(dbgs() << "-------------------------------------------------------"
101 "----------------------\n");
102 LLVM_DEBUG(dbgs() << "collectAllFuncUnits");
jmolloy39525a62019-11-04 19:25:13 +0000103 LLVM_DEBUG(dbgs() << " (" << ProcModels.size() << " itineraries)\n");
104
105 std::set<Record *> ProcItinList;
106 for (const CodeGenProcModel *Model : ProcModels)
107 ProcItinList.insert(Model->ItinsDef);
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +0000108
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +0000109 int totalFUs = 0;
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +0000110 // Parse functional units for all the itineraries.
jmolloy39525a62019-11-04 19:25:13 +0000111 for (Record *Proc : ProcItinList) {
112 std::vector<Record *> FUs = Proc->getValueAsListOfDefs("FU");
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +0000113
jmolloy39525a62019-11-04 19:25:13 +0000114 LLVM_DEBUG(dbgs() << " FU:"
115 << " (" << FUs.size() << " FUs) " << Proc->getName());
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +0000116
Sebastian Pop9aa61372011-12-06 17:34:11 +0000117 // Convert macros to bits for each stage.
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +0000118 unsigned numFUs = FUs.size();
119 for (unsigned j = 0; j < numFUs; ++j) {
jmolloy39525a62019-11-04 19:25:13 +0000120 assert((j < DFA_MAX_RESOURCES) &&
121 "Exceeded maximum number of representable resources");
122 uint64_t FuncResources = 1ULL << j;
Benjamin Krameradcd0262020-01-28 20:23:46 +0100123 FUNameToBitsMap[std::string(FUs[j]->getName())] = FuncResources;
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000124 LLVM_DEBUG(dbgs() << " " << FUs[j]->getName() << ":0x"
125 << Twine::utohexstr(FuncResources));
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +0000126 }
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +0000127 totalFUs += numFUs;
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000128 LLVM_DEBUG(dbgs() << "\n");
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +0000129 }
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +0000130 return totalFUs;
131}
132
jmolloy39525a62019-11-04 19:25:13 +0000133int DFAPacketizerEmitter::collectAllComboFuncs(ArrayRef<Record *> ComboFuncList) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000134 LLVM_DEBUG(dbgs() << "-------------------------------------------------------"
135 "----------------------\n");
136 LLVM_DEBUG(dbgs() << "collectAllComboFuncs");
137 LLVM_DEBUG(dbgs() << " (" << ComboFuncList.size() << " sets)\n");
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +0000138
139 int numCombos = 0;
140 for (unsigned i = 0, N = ComboFuncList.size(); i < N; ++i) {
141 Record *Func = ComboFuncList[i];
jmolloy39525a62019-11-04 19:25:13 +0000142 std::vector<Record *> FUs = Func->getValueAsListOfDefs("CFD");
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +0000143
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000144 LLVM_DEBUG(dbgs() << " CFD:" << i << " (" << FUs.size() << " combo FUs) "
145 << Func->getName() << "\n");
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +0000146
147 // Convert macros to bits for each stage.
148 for (unsigned j = 0, N = FUs.size(); j < N; ++j) {
jmolloy39525a62019-11-04 19:25:13 +0000149 assert((j < DFA_MAX_RESOURCES) &&
150 "Exceeded maximum number of DFA resources");
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +0000151 Record *FuncData = FUs[j];
152 Record *ComboFunc = FuncData->getValueAsDef("TheComboFunc");
jmolloy39525a62019-11-04 19:25:13 +0000153 const std::vector<Record *> &FuncList =
154 FuncData->getValueAsListOfDefs("FuncList");
Benjamin Krameradcd0262020-01-28 20:23:46 +0100155 const std::string &ComboFuncName = std::string(ComboFunc->getName());
jmolloy39525a62019-11-04 19:25:13 +0000156 uint64_t ComboBit = FUNameToBitsMap[ComboFuncName];
157 uint64_t ComboResources = ComboBit;
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000158 LLVM_DEBUG(dbgs() << " combo: " << ComboFuncName << ":0x"
159 << Twine::utohexstr(ComboResources) << "\n");
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +0000160 for (unsigned k = 0, M = FuncList.size(); k < M; ++k) {
Benjamin Krameradcd0262020-01-28 20:23:46 +0100161 std::string FuncName = std::string(FuncList[k]->getName());
jmolloy39525a62019-11-04 19:25:13 +0000162 uint64_t FuncResources = FUNameToBitsMap[FuncName];
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000163 LLVM_DEBUG(dbgs() << " " << FuncName << ":0x"
164 << Twine::utohexstr(FuncResources) << "\n");
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +0000165 ComboResources |= FuncResources;
166 }
167 ComboBitToBitsMap[ComboBit] = ComboResources;
168 numCombos++;
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000169 LLVM_DEBUG(dbgs() << " => combo bits: " << ComboFuncName << ":0x"
170 << Twine::utohexstr(ComboBit) << " = 0x"
171 << Twine::utohexstr(ComboResources) << "\n");
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +0000172 }
173 }
174 return numCombos;
175}
176
jmolloy39525a62019-11-04 19:25:13 +0000177ResourceVector
178DFAPacketizerEmitter::getResourcesForItinerary(Record *Itinerary) {
179 ResourceVector Resources;
180 assert(Itinerary);
181 for (Record *StageDef : Itinerary->getValueAsListOfDefs("Stages")) {
182 uint64_t StageResources = 0;
183 for (Record *Unit : StageDef->getValueAsListOfDefs("Units")) {
Benjamin Krameradcd0262020-01-28 20:23:46 +0100184 StageResources |= FUNameToBitsMap[std::string(Unit->getName())];
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +0000185 }
jmolloy39525a62019-11-04 19:25:13 +0000186 if (StageResources != 0)
187 Resources.push_back(StageResources);
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +0000188 }
jmolloy39525a62019-11-04 19:25:13 +0000189 return Resources;
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +0000190}
191
jmolloy39525a62019-11-04 19:25:13 +0000192void DFAPacketizerEmitter::createScheduleClasses(unsigned ItineraryIdx,
193 const RecVec &Itineraries) {
194 unsigned Idx = 0;
195 for (Record *Itinerary : Itineraries) {
196 if (!Itinerary) {
197 ScheduleClasses.push_back({ItineraryIdx, Idx++, 0, ResourceVector{}});
198 continue;
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +0000199 }
jmolloy39525a62019-11-04 19:25:13 +0000200 ResourceVector Resources = getResourcesForItinerary(Itinerary);
201 ScheduleClasses.push_back(
202 {ItineraryIdx, Idx++, UniqueResources.insert(Resources), Resources});
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +0000203 }
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +0000204}
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +0000205
206//
Sebastian Pop9aa61372011-12-06 17:34:11 +0000207// Run the worklist algorithm to generate the DFA.
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +0000208//
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +0000209void DFAPacketizerEmitter::run(raw_ostream &OS) {
James Molloy6ccd6732019-08-30 19:50:49 +0000210 OS << "\n"
211 << "#include \"llvm/CodeGen/DFAPacketizer.h\"\n";
212 OS << "namespace llvm {\n";
213
jmolloy39525a62019-11-04 19:25:13 +0000214 CodeGenTarget CGT(Records);
215 CodeGenSchedModels CGS(Records, CGT);
James Molloy6ccd6732019-08-30 19:50:49 +0000216
jmolloy39525a62019-11-04 19:25:13 +0000217 std::unordered_map<std::string, std::vector<const CodeGenProcModel *>>
218 ItinsByNamespace;
219 for (const CodeGenProcModel &ProcModel : CGS.procModels()) {
220 if (ProcModel.hasItineraries()) {
221 auto NS = ProcModel.ItinsDef->getValueAsString("PacketizerNamespace");
Benjamin Krameradcd0262020-01-28 20:23:46 +0100222 ItinsByNamespace[std::string(NS)].push_back(&ProcModel);
jmolloy39525a62019-11-04 19:25:13 +0000223 }
224 }
James Molloy6ccd6732019-08-30 19:50:49 +0000225
226 for (auto &KV : ItinsByNamespace)
227 emitForItineraries(OS, KV.second, KV.first);
228 OS << "} // end namespace llvm\n";
229}
230
231void DFAPacketizerEmitter::emitForItineraries(
jmolloy39525a62019-11-04 19:25:13 +0000232 raw_ostream &OS, std::vector<const CodeGenProcModel *> &ProcModels,
James Molloy6ccd6732019-08-30 19:50:49 +0000233 std::string DFAName) {
jmolloy39525a62019-11-04 19:25:13 +0000234 OS << "} // end namespace llvm\n\n";
235 OS << "namespace {\n";
236 collectAllFuncUnits(ProcModels);
237 collectAllComboFuncs(Records.getAllDerivedDefinitions("ComboFuncUnits"));
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +0000238
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +0000239 // Collect the itineraries.
jmolloy39525a62019-11-04 19:25:13 +0000240 DenseMap<const CodeGenProcModel *, unsigned> ProcModelStartIdx;
241 for (const CodeGenProcModel *Model : ProcModels) {
242 assert(Model->hasItineraries());
243 ProcModelStartIdx[Model] = ScheduleClasses.size();
244 createScheduleClasses(Model->Index, Model->ItinDefList);
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +0000245 }
246
jmolloy39525a62019-11-04 19:25:13 +0000247 // Output the mapping from ScheduleClass to ResourcesIdx.
248 unsigned Idx = 0;
249 OS << "unsigned " << TargetName << DFAName << "ResourceIndices[] = {";
250 for (const ScheduleClass &SC : ScheduleClasses) {
251 if (Idx++ % 32 == 0)
252 OS << "\n ";
253 OS << SC.ResourcesIdx << ", ";
254 }
255 OS << "\n};\n\n";
256
257 // And the mapping from Itinerary index into the previous table.
258 OS << "unsigned " << TargetName << DFAName
259 << "ProcResourceIndexStart[] = {\n";
260 OS << " 0, // NoSchedModel\n";
261 for (const CodeGenProcModel *Model : ProcModels) {
262 OS << " " << ProcModelStartIdx[Model] << ", // " << Model->ModelName
263 << "\n";
264 }
265 OS << ScheduleClasses.size() << "\n};\n\n";
266
James Molloy12092a92019-10-17 08:34:29 +0000267 // The type of a state in the nondeterministic automaton we're defining.
jmolloy39525a62019-11-04 19:25:13 +0000268 using NfaStateTy = uint64_t;
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +0000269
James Molloy12092a92019-10-17 08:34:29 +0000270 // Given a resource state, return all resource states by applying
271 // InsnClass.
jmolloy39525a62019-11-04 19:25:13 +0000272 auto applyInsnClass = [&](const ResourceVector &InsnClass,
273 NfaStateTy State) -> std::deque<NfaStateTy> {
274 std::deque<NfaStateTy> V(1, State);
James Molloy12092a92019-10-17 08:34:29 +0000275 // Apply every stage in the class individually.
jmolloy39525a62019-11-04 19:25:13 +0000276 for (NfaStateTy Stage : InsnClass) {
James Molloy12092a92019-10-17 08:34:29 +0000277 // Apply this stage to every existing member of V in turn.
278 size_t Sz = V.size();
279 for (unsigned I = 0; I < Sz; ++I) {
jmolloy39525a62019-11-04 19:25:13 +0000280 NfaStateTy S = V.front();
James Molloy12092a92019-10-17 08:34:29 +0000281 V.pop_front();
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +0000282
James Molloy12092a92019-10-17 08:34:29 +0000283 // For this stage, state combination, try all possible resources.
284 for (unsigned J = 0; J < DFA_MAX_RESOURCES; ++J) {
jmolloy39525a62019-11-04 19:25:13 +0000285 NfaStateTy ResourceMask = 1ULL << J;
James Molloy12092a92019-10-17 08:34:29 +0000286 if ((ResourceMask & Stage) == 0)
287 // This resource isn't required by this stage.
288 continue;
jmolloy39525a62019-11-04 19:25:13 +0000289 NfaStateTy Combo = ComboBitToBitsMap[ResourceMask];
James Molloy12092a92019-10-17 08:34:29 +0000290 if (Combo && ((~S & Combo) != Combo))
291 // This combo units bits are not available.
292 continue;
jmolloy39525a62019-11-04 19:25:13 +0000293 NfaStateTy ResultingResourceState = S | ResourceMask | Combo;
James Molloy12092a92019-10-17 08:34:29 +0000294 if (ResultingResourceState == S)
295 continue;
296 V.push_back(ResultingResourceState);
297 }
298 }
299 }
300 return V;
301 };
302
303 // Given a resource state, return a quick (conservative) guess as to whether
304 // InsnClass can be applied. This is a filter for the more heavyweight
305 // applyInsnClass.
jmolloy39525a62019-11-04 19:25:13 +0000306 auto canApplyInsnClass = [](const ResourceVector &InsnClass,
James Molloy12092a92019-10-17 08:34:29 +0000307 NfaStateTy State) -> bool {
jmolloy39525a62019-11-04 19:25:13 +0000308 for (NfaStateTy Resources : InsnClass) {
James Molloy12092a92019-10-17 08:34:29 +0000309 if ((State | Resources) == State)
310 return false;
311 }
312 return true;
313 };
314
315 DfaEmitter Emitter;
316 std::deque<NfaStateTy> Worklist(1, 0);
317 std::set<NfaStateTy> SeenStates;
318 SeenStates.insert(Worklist.front());
319 while (!Worklist.empty()) {
320 NfaStateTy State = Worklist.front();
321 Worklist.pop_front();
jmolloy39525a62019-11-04 19:25:13 +0000322 for (const ResourceVector &Resources : UniqueResources) {
323 if (!canApplyInsnClass(Resources, State))
James Molloy12092a92019-10-17 08:34:29 +0000324 continue;
jmolloy39525a62019-11-04 19:25:13 +0000325 unsigned ResourcesID = UniqueResources.idFor(Resources);
326 for (uint64_t NewState : applyInsnClass(Resources, State)) {
James Molloy12092a92019-10-17 08:34:29 +0000327 if (SeenStates.emplace(NewState).second)
328 Worklist.emplace_back(NewState);
jmolloy39525a62019-11-04 19:25:13 +0000329 Emitter.addTransition(State, NewState, ResourcesID);
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +0000330 }
331 }
332 }
333
James Molloy12092a92019-10-17 08:34:29 +0000334 std::string TargetAndDFAName = TargetName + DFAName;
335 Emitter.emit(TargetAndDFAName, OS);
336 OS << "} // end anonymous namespace\n\n";
James Molloy6ccd6732019-08-30 19:50:49 +0000337
338 std::string SubTargetClassName = TargetName + "GenSubtargetInfo";
339 OS << "namespace llvm {\n";
340 OS << "DFAPacketizer *" << SubTargetClassName << "::"
341 << "create" << DFAName
342 << "DFAPacketizer(const InstrItineraryData *IID) const {\n"
James Molloyd5afdbe2019-10-18 14:48:35 +0000343 << " static Automaton<uint64_t> A(ArrayRef<" << TargetAndDFAName
James Molloy12092a92019-10-17 08:34:29 +0000344 << "Transition>(" << TargetAndDFAName << "Transitions), "
345 << TargetAndDFAName << "TransitionInfo);\n"
jmolloy39525a62019-11-04 19:25:13 +0000346 << " unsigned ProcResIdxStart = " << TargetAndDFAName
347 << "ProcResourceIndexStart[IID->SchedModel.ProcID];\n"
348 << " unsigned ProcResIdxNum = " << TargetAndDFAName
349 << "ProcResourceIndexStart[IID->SchedModel.ProcID + 1] - "
350 "ProcResIdxStart;\n"
351 << " return new DFAPacketizer(IID, A, {&" << TargetAndDFAName
352 << "ResourceIndices[ProcResIdxStart], ProcResIdxNum});\n"
James Molloy12092a92019-10-17 08:34:29 +0000353 << "\n}\n\n";
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +0000354}
Jakob Stoklund Olesene6aed132012-06-11 15:37:55 +0000355
356namespace llvm {
357
358void EmitDFAPacketizer(RecordKeeper &RK, raw_ostream &OS) {
359 emitSourceFileHeader("Target DFA Packetizer Tables", OS);
360 DFAPacketizerEmitter(RK).run(OS);
361}
362
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +0000363} // end namespace llvm