blob: 3a30b28d669b466b59206b3da6769846263b2784 [file] [log] [blame]
Andrew Trick87255e32012-07-07 04:00:00 +00001//===- CodeGenSchedule.cpp - Scheduling MachineModels ---------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Alp Tokercb402912014-01-24 17:20:08 +000010// This file defines structures to encapsulate the machine model as described in
Andrew Trick87255e32012-07-07 04:00:00 +000011// the target description.
12//
13//===----------------------------------------------------------------------===//
14
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +000015#include "CodeGenInstruction.h"
Andrew Trick87255e32012-07-07 04:00:00 +000016#include "CodeGenSchedule.h"
17#include "CodeGenTarget.h"
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +000018#include "llvm/ADT/SmallPtrSet.h"
19#include "llvm/ADT/SmallSet.h"
20#include "llvm/ADT/SmallVector.h"
Chandler Carruth91d19d82012-12-04 10:37:14 +000021#include "llvm/ADT/STLExtras.h"
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +000022#include "llvm/Support/Casting.h"
Andrew Trick87255e32012-07-07 04:00:00 +000023#include "llvm/Support/Debug.h"
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +000024#include "llvm/Support/raw_ostream.h"
Andrew Trick9e1deb62012-10-03 23:06:32 +000025#include "llvm/Support/Regex.h"
Chandler Carruth91d19d82012-12-04 10:37:14 +000026#include "llvm/TableGen/Error.h"
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +000027#include <algorithm>
28#include <iterator>
29#include <utility>
Andrew Trick87255e32012-07-07 04:00:00 +000030
31using namespace llvm;
32
Chandler Carruth97acce22014-04-22 03:06:00 +000033#define DEBUG_TYPE "subtarget-emitter"
34
Andrew Trick76686492012-09-15 00:19:57 +000035#ifndef NDEBUG
Benjamin Kramere1761952015-10-24 12:46:49 +000036static void dumpIdxVec(ArrayRef<unsigned> V) {
37 for (unsigned Idx : V)
38 dbgs() << Idx << ", ";
Andrew Trick33401e82012-09-15 00:19:59 +000039}
Andrew Trick76686492012-09-15 00:19:57 +000040#endif
41
Juergen Ributzka05c5a932013-11-19 03:08:35 +000042namespace {
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +000043
Andrew Trick9e1deb62012-10-03 23:06:32 +000044// (instrs a, b, ...) Evaluate and union all arguments. Identical to AddOp.
45struct InstrsOp : public SetTheory::Operator {
Craig Topper716b0732014-03-05 05:17:42 +000046 void apply(SetTheory &ST, DagInit *Expr, SetTheory::RecSet &Elts,
47 ArrayRef<SMLoc> Loc) override {
Juergen Ributzka05c5a932013-11-19 03:08:35 +000048 ST.evaluate(Expr->arg_begin(), Expr->arg_end(), Elts, Loc);
49 }
50};
Juergen Ributzkad12ccbd2013-11-19 00:57:56 +000051
Andrew Trick9e1deb62012-10-03 23:06:32 +000052// (instregex "OpcPat",...) Find all instructions matching an opcode pattern.
53//
54// TODO: Since this is a prefix match, perform a binary search over the
55// instruction names using lower_bound. Note that the predefined instrs must be
56// scanned linearly first. However, this is only safe if the regex pattern has
57// no top-level bars. The DAG already has a list of patterns, so there's no
58// reason to use top-level bars, but we need a way to verify they don't exist
59// before implementing the optimization.
60struct InstRegexOp : public SetTheory::Operator {
61 const CodeGenTarget &Target;
62 InstRegexOp(const CodeGenTarget &t): Target(t) {}
63
Juergen Ributzka05c5a932013-11-19 03:08:35 +000064 void apply(SetTheory &ST, DagInit *Expr, SetTheory::RecSet &Elts,
Craig Topper716b0732014-03-05 05:17:42 +000065 ArrayRef<SMLoc> Loc) override {
David Blaikie80721252014-04-21 21:49:08 +000066 SmallVector<Regex, 4> RegexList;
Javed Absarfc500042017-10-05 13:27:43 +000067 for (Init *Arg : make_range(Expr->arg_begin(), Expr->arg_end())) {
68 StringInit *SI = dyn_cast<StringInit>(Arg);
Juergen Ributzka05c5a932013-11-19 03:08:35 +000069 if (!SI)
70 PrintFatalError(Loc, "instregex requires pattern string: "
71 + Expr->getAsString());
72 std::string pat = SI->getValue();
73 // Implement a python-style prefix match.
74 if (pat[0] != '^') {
75 pat.insert(0, "^(");
76 pat.insert(pat.end(), ')');
77 }
David Blaikie80721252014-04-21 21:49:08 +000078 RegexList.push_back(Regex(pat));
Juergen Ributzka05c5a932013-11-19 03:08:35 +000079 }
Craig Topper8cc904d2016-01-17 20:38:18 +000080 for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) {
David Blaikie80721252014-04-21 21:49:08 +000081 for (auto &R : RegexList) {
Craig Topper8a417c12014-12-09 08:05:51 +000082 if (R.match(Inst->TheDef->getName()))
83 Elts.insert(Inst->TheDef);
Juergen Ributzka05c5a932013-11-19 03:08:35 +000084 }
85 }
Juergen Ributzka05c5a932013-11-19 03:08:35 +000086 }
Andrew Trick9e1deb62012-10-03 23:06:32 +000087};
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +000088
Juergen Ributzka05c5a932013-11-19 03:08:35 +000089} // end anonymous namespace
Juergen Ributzkad12ccbd2013-11-19 00:57:56 +000090
Andrew Trick76686492012-09-15 00:19:57 +000091/// CodeGenModels ctor interprets machine model records and populates maps.
Andrew Trick87255e32012-07-07 04:00:00 +000092CodeGenSchedModels::CodeGenSchedModels(RecordKeeper &RK,
93 const CodeGenTarget &TGT):
Andrew Trickbf8a28d2013-03-16 18:58:55 +000094 Records(RK), Target(TGT) {
Andrew Trick87255e32012-07-07 04:00:00 +000095
Andrew Trick9e1deb62012-10-03 23:06:32 +000096 Sets.addFieldExpander("InstRW", "Instrs");
97
98 // Allow Set evaluation to recognize the dags used in InstRW records:
99 // (instrs Op1, Op1...)
Craig Topperba6057d2015-04-24 06:49:44 +0000100 Sets.addOperator("instrs", llvm::make_unique<InstrsOp>());
101 Sets.addOperator("instregex", llvm::make_unique<InstRegexOp>(Target));
Andrew Trick9e1deb62012-10-03 23:06:32 +0000102
Andrew Trick76686492012-09-15 00:19:57 +0000103 // Instantiate a CodeGenProcModel for each SchedMachineModel with the values
104 // that are explicitly referenced in tablegen records. Resources associated
105 // with each processor will be derived later. Populate ProcModelMap with the
106 // CodeGenProcModel instances.
107 collectProcModels();
Andrew Trick87255e32012-07-07 04:00:00 +0000108
Andrew Trick76686492012-09-15 00:19:57 +0000109 // Instantiate a CodeGenSchedRW for each SchedReadWrite record explicitly
110 // defined, and populate SchedReads and SchedWrites vectors. Implicit
111 // SchedReadWrites that represent sequences derived from expanded variant will
112 // be inferred later.
113 collectSchedRW();
114
115 // Instantiate a CodeGenSchedClass for each unique SchedRW signature directly
116 // required by an instruction definition, and populate SchedClassIdxMap. Set
117 // NumItineraryClasses to the number of explicit itinerary classes referenced
118 // by instructions. Set NumInstrSchedClasses to the number of itinerary
119 // classes plus any classes implied by instructions that derive from class
120 // Sched and provide SchedRW list. This does not infer any new classes from
121 // SchedVariant.
122 collectSchedClasses();
123
124 // Find instruction itineraries for each processor. Sort and populate
Andrew Trick9257b8f2012-09-22 02:24:21 +0000125 // CodeGenProcModel::ItinDefList. (Cycle-to-cycle itineraries). This requires
Andrew Trick76686492012-09-15 00:19:57 +0000126 // all itinerary classes to be discovered.
127 collectProcItins();
128
129 // Find ItinRW records for each processor and itinerary class.
130 // (For per-operand resources mapped to itinerary classes).
131 collectProcItinRW();
Andrew Trick33401e82012-09-15 00:19:59 +0000132
Simon Dardis5f95c9a2016-06-24 08:43:27 +0000133 // Find UnsupportedFeatures records for each processor.
134 // (For per-operand resources mapped to itinerary classes).
135 collectProcUnsupportedFeatures();
136
Andrew Trick33401e82012-09-15 00:19:59 +0000137 // Infer new SchedClasses from SchedVariant.
138 inferSchedClasses();
139
Andrew Trick1e46d482012-09-15 00:20:02 +0000140 // Populate each CodeGenProcModel's WriteResDefs, ReadAdvanceDefs, and
141 // ProcResourceDefs.
Joel Jones80372332017-06-28 00:06:40 +0000142 DEBUG(dbgs() << "\n+++ RESOURCE DEFINITIONS (collectProcResources) +++\n");
Andrew Trick1e46d482012-09-15 00:20:02 +0000143 collectProcResources();
Matthias Braun17cb5792016-03-01 20:03:21 +0000144
145 checkCompleteness();
Andrew Trick87255e32012-07-07 04:00:00 +0000146}
147
Andrew Trick76686492012-09-15 00:19:57 +0000148/// Gather all processor models.
149void CodeGenSchedModels::collectProcModels() {
150 RecVec ProcRecords = Records.getAllDerivedDefinitions("Processor");
151 std::sort(ProcRecords.begin(), ProcRecords.end(), LessRecordFieldName());
Andrew Trick87255e32012-07-07 04:00:00 +0000152
Andrew Trick76686492012-09-15 00:19:57 +0000153 // Reserve space because we can. Reallocation would be ok.
154 ProcModels.reserve(ProcRecords.size()+1);
155
156 // Use idx=0 for NoModel/NoItineraries.
157 Record *NoModelDef = Records.getDef("NoSchedModel");
158 Record *NoItinsDef = Records.getDef("NoItineraries");
Benjamin Kramerf5e2fc42015-05-29 19:43:39 +0000159 ProcModels.emplace_back(0, "NoSchedModel", NoModelDef, NoItinsDef);
Andrew Trick76686492012-09-15 00:19:57 +0000160 ProcModelMap[NoModelDef] = 0;
161
162 // For each processor, find a unique machine model.
Joel Jones80372332017-06-28 00:06:40 +0000163 DEBUG(dbgs() << "+++ PROCESSOR MODELs (addProcModel) +++\n");
Javed Absar67b042c2017-09-13 10:31:10 +0000164 for (Record *ProcRecord : ProcRecords)
165 addProcModel(ProcRecord);
Andrew Trick76686492012-09-15 00:19:57 +0000166}
167
168/// Get a unique processor model based on the defined MachineModel and
169/// ProcessorItineraries.
170void CodeGenSchedModels::addProcModel(Record *ProcDef) {
171 Record *ModelKey = getModelOrItinDef(ProcDef);
172 if (!ProcModelMap.insert(std::make_pair(ModelKey, ProcModels.size())).second)
173 return;
174
175 std::string Name = ModelKey->getName();
176 if (ModelKey->isSubClassOf("SchedMachineModel")) {
177 Record *ItinsDef = ModelKey->getValueAsDef("Itineraries");
Benjamin Kramerf5e2fc42015-05-29 19:43:39 +0000178 ProcModels.emplace_back(ProcModels.size(), Name, ModelKey, ItinsDef);
Andrew Trick76686492012-09-15 00:19:57 +0000179 }
180 else {
181 // An itinerary is defined without a machine model. Infer a new model.
182 if (!ModelKey->getValueAsListOfDefs("IID").empty())
183 Name = Name + "Model";
Benjamin Kramerf5e2fc42015-05-29 19:43:39 +0000184 ProcModels.emplace_back(ProcModels.size(), Name,
185 ProcDef->getValueAsDef("SchedModel"), ModelKey);
Andrew Trick76686492012-09-15 00:19:57 +0000186 }
187 DEBUG(ProcModels.back().dump());
188}
189
190// Recursively find all reachable SchedReadWrite records.
191static void scanSchedRW(Record *RWDef, RecVec &RWDefs,
192 SmallPtrSet<Record*, 16> &RWSet) {
David Blaikie70573dc2014-11-19 07:49:26 +0000193 if (!RWSet.insert(RWDef).second)
Andrew Trick76686492012-09-15 00:19:57 +0000194 return;
195 RWDefs.push_back(RWDef);
Javed Absar67b042c2017-09-13 10:31:10 +0000196 // Reads don't currently have sequence records, but it can be added later.
Andrew Trick76686492012-09-15 00:19:57 +0000197 if (RWDef->isSubClassOf("WriteSequence")) {
198 RecVec Seq = RWDef->getValueAsListOfDefs("Writes");
Javed Absar67b042c2017-09-13 10:31:10 +0000199 for (Record *WSRec : Seq)
200 scanSchedRW(WSRec, RWDefs, RWSet);
Andrew Trick76686492012-09-15 00:19:57 +0000201 }
202 else if (RWDef->isSubClassOf("SchedVariant")) {
203 // Visit each variant (guarded by a different predicate).
204 RecVec Vars = RWDef->getValueAsListOfDefs("Variants");
Javed Absar67b042c2017-09-13 10:31:10 +0000205 for (Record *Variant : Vars) {
Andrew Trick76686492012-09-15 00:19:57 +0000206 // Visit each RW in the sequence selected by the current variant.
Javed Absar67b042c2017-09-13 10:31:10 +0000207 RecVec Selected = Variant->getValueAsListOfDefs("Selected");
208 for (Record *SelDef : Selected)
209 scanSchedRW(SelDef, RWDefs, RWSet);
Andrew Trick76686492012-09-15 00:19:57 +0000210 }
211 }
212}
213
214// Collect and sort all SchedReadWrites reachable via tablegen records.
215// More may be inferred later when inferring new SchedClasses from variants.
216void CodeGenSchedModels::collectSchedRW() {
217 // Reserve idx=0 for invalid writes/reads.
218 SchedWrites.resize(1);
219 SchedReads.resize(1);
220
221 SmallPtrSet<Record*, 16> RWSet;
222
223 // Find all SchedReadWrites referenced by instruction defs.
224 RecVec SWDefs, SRDefs;
Craig Topper8cc904d2016-01-17 20:38:18 +0000225 for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) {
Craig Topper8a417c12014-12-09 08:05:51 +0000226 Record *SchedDef = Inst->TheDef;
Jakob Stoklund Olesena4a361d2013-03-15 22:51:13 +0000227 if (SchedDef->isValueUnset("SchedRW"))
Andrew Trick76686492012-09-15 00:19:57 +0000228 continue;
229 RecVec RWs = SchedDef->getValueAsListOfDefs("SchedRW");
Javed Absar67b042c2017-09-13 10:31:10 +0000230 for (Record *RW : RWs) {
231 if (RW->isSubClassOf("SchedWrite"))
232 scanSchedRW(RW, SWDefs, RWSet);
Andrew Trick76686492012-09-15 00:19:57 +0000233 else {
Javed Absar67b042c2017-09-13 10:31:10 +0000234 assert(RW->isSubClassOf("SchedRead") && "Unknown SchedReadWrite");
235 scanSchedRW(RW, SRDefs, RWSet);
Andrew Trick76686492012-09-15 00:19:57 +0000236 }
237 }
238 }
239 // Find all ReadWrites referenced by InstRW.
240 RecVec InstRWDefs = Records.getAllDerivedDefinitions("InstRW");
Javed Absar67b042c2017-09-13 10:31:10 +0000241 for (Record *InstRWDef : InstRWDefs) {
Andrew Trick76686492012-09-15 00:19:57 +0000242 // For all OperandReadWrites.
Javed Absar67b042c2017-09-13 10:31:10 +0000243 RecVec RWDefs = InstRWDef->getValueAsListOfDefs("OperandReadWrites");
244 for (Record *RWDef : RWDefs) {
245 if (RWDef->isSubClassOf("SchedWrite"))
246 scanSchedRW(RWDef, SWDefs, RWSet);
Andrew Trick76686492012-09-15 00:19:57 +0000247 else {
Javed Absar67b042c2017-09-13 10:31:10 +0000248 assert(RWDef->isSubClassOf("SchedRead") && "Unknown SchedReadWrite");
249 scanSchedRW(RWDef, SRDefs, RWSet);
Andrew Trick76686492012-09-15 00:19:57 +0000250 }
251 }
252 }
253 // Find all ReadWrites referenced by ItinRW.
254 RecVec ItinRWDefs = Records.getAllDerivedDefinitions("ItinRW");
Javed Absar67b042c2017-09-13 10:31:10 +0000255 for (Record *ItinRWDef : ItinRWDefs) {
Andrew Trick76686492012-09-15 00:19:57 +0000256 // For all OperandReadWrites.
Javed Absar67b042c2017-09-13 10:31:10 +0000257 RecVec RWDefs = ItinRWDef->getValueAsListOfDefs("OperandReadWrites");
258 for (Record *RWDef : RWDefs) {
259 if (RWDef->isSubClassOf("SchedWrite"))
260 scanSchedRW(RWDef, SWDefs, RWSet);
Andrew Trick76686492012-09-15 00:19:57 +0000261 else {
Javed Absar67b042c2017-09-13 10:31:10 +0000262 assert(RWDef->isSubClassOf("SchedRead") && "Unknown SchedReadWrite");
263 scanSchedRW(RWDef, SRDefs, RWSet);
Andrew Trick76686492012-09-15 00:19:57 +0000264 }
265 }
266 }
Andrew Trick9257b8f2012-09-22 02:24:21 +0000267 // Find all ReadWrites referenced by SchedAlias. AliasDefs needs to be sorted
268 // for the loop below that initializes Alias vectors.
269 RecVec AliasDefs = Records.getAllDerivedDefinitions("SchedAlias");
270 std::sort(AliasDefs.begin(), AliasDefs.end(), LessRecord());
Javed Absar67b042c2017-09-13 10:31:10 +0000271 for (Record *ADef : AliasDefs) {
272 Record *MatchDef = ADef->getValueAsDef("MatchRW");
273 Record *AliasDef = ADef->getValueAsDef("AliasRW");
Andrew Trick9257b8f2012-09-22 02:24:21 +0000274 if (MatchDef->isSubClassOf("SchedWrite")) {
275 if (!AliasDef->isSubClassOf("SchedWrite"))
Javed Absar67b042c2017-09-13 10:31:10 +0000276 PrintFatalError(ADef->getLoc(), "SchedWrite Alias must be SchedWrite");
Andrew Trick9257b8f2012-09-22 02:24:21 +0000277 scanSchedRW(AliasDef, SWDefs, RWSet);
278 }
279 else {
280 assert(MatchDef->isSubClassOf("SchedRead") && "Unknown SchedReadWrite");
281 if (!AliasDef->isSubClassOf("SchedRead"))
Javed Absar67b042c2017-09-13 10:31:10 +0000282 PrintFatalError(ADef->getLoc(), "SchedRead Alias must be SchedRead");
Andrew Trick9257b8f2012-09-22 02:24:21 +0000283 scanSchedRW(AliasDef, SRDefs, RWSet);
284 }
285 }
Andrew Trick76686492012-09-15 00:19:57 +0000286 // Sort and add the SchedReadWrites directly referenced by instructions or
287 // itinerary resources. Index reads and writes in separate domains.
288 std::sort(SWDefs.begin(), SWDefs.end(), LessRecord());
Javed Absar67b042c2017-09-13 10:31:10 +0000289 for (Record *SWDef : SWDefs) {
290 assert(!getSchedRWIdx(SWDef, /*IsRead=*/false) && "duplicate SchedWrite");
291 SchedWrites.emplace_back(SchedWrites.size(), SWDef);
Andrew Trick76686492012-09-15 00:19:57 +0000292 }
293 std::sort(SRDefs.begin(), SRDefs.end(), LessRecord());
Javed Absar67b042c2017-09-13 10:31:10 +0000294 for (Record *SRDef : SRDefs) {
295 assert(!getSchedRWIdx(SRDef, /*IsRead-*/true) && "duplicate SchedWrite");
296 SchedReads.emplace_back(SchedReads.size(), SRDef);
Andrew Trick76686492012-09-15 00:19:57 +0000297 }
298 // Initialize WriteSequence vectors.
Javed Absar67b042c2017-09-13 10:31:10 +0000299 for (CodeGenSchedRW &CGRW : SchedWrites) {
300 if (!CGRW.IsSequence)
Andrew Trick76686492012-09-15 00:19:57 +0000301 continue;
Javed Absar67b042c2017-09-13 10:31:10 +0000302 findRWs(CGRW.TheDef->getValueAsListOfDefs("Writes"), CGRW.Sequence,
Andrew Trick76686492012-09-15 00:19:57 +0000303 /*IsRead=*/false);
304 }
Andrew Trick9257b8f2012-09-22 02:24:21 +0000305 // Initialize Aliases vectors.
Javed Absar67b042c2017-09-13 10:31:10 +0000306 for (Record *ADef : AliasDefs) {
307 Record *AliasDef = ADef->getValueAsDef("AliasRW");
Andrew Trick9257b8f2012-09-22 02:24:21 +0000308 getSchedRW(AliasDef).IsAlias = true;
Javed Absar67b042c2017-09-13 10:31:10 +0000309 Record *MatchDef = ADef->getValueAsDef("MatchRW");
Andrew Trick9257b8f2012-09-22 02:24:21 +0000310 CodeGenSchedRW &RW = getSchedRW(MatchDef);
311 if (RW.IsAlias)
Javed Absar67b042c2017-09-13 10:31:10 +0000312 PrintFatalError(ADef->getLoc(), "Cannot Alias an Alias");
313 RW.Aliases.push_back(ADef);
Andrew Trick9257b8f2012-09-22 02:24:21 +0000314 }
Andrew Trick76686492012-09-15 00:19:57 +0000315 DEBUG(
Joel Jones80372332017-06-28 00:06:40 +0000316 dbgs() << "\n+++ SCHED READS and WRITES (collectSchedRW) +++\n";
Andrew Trick76686492012-09-15 00:19:57 +0000317 for (unsigned WIdx = 0, WEnd = SchedWrites.size(); WIdx != WEnd; ++WIdx) {
318 dbgs() << WIdx << ": ";
319 SchedWrites[WIdx].dump();
320 dbgs() << '\n';
321 }
322 for (unsigned RIdx = 0, REnd = SchedReads.size(); RIdx != REnd; ++RIdx) {
323 dbgs() << RIdx << ": ";
324 SchedReads[RIdx].dump();
325 dbgs() << '\n';
326 }
327 RecVec RWDefs = Records.getAllDerivedDefinitions("SchedReadWrite");
Javed Absar67b042c2017-09-13 10:31:10 +0000328 for (Record *RWDef : RWDefs) {
329 if (!getSchedRWIdx(RWDef, RWDef->isSubClassOf("SchedRead"))) {
330 const std::string &Name = RWDef->getName();
Andrew Trick76686492012-09-15 00:19:57 +0000331 if (Name != "NoWrite" && Name != "ReadDefault")
Javed Absar67b042c2017-09-13 10:31:10 +0000332 dbgs() << "Unused SchedReadWrite " << RWDef->getName() << '\n';
Andrew Trick76686492012-09-15 00:19:57 +0000333 }
334 });
335}
336
337/// Compute a SchedWrite name from a sequence of writes.
Benjamin Kramere1761952015-10-24 12:46:49 +0000338std::string CodeGenSchedModels::genRWName(ArrayRef<unsigned> Seq, bool IsRead) {
Andrew Trick76686492012-09-15 00:19:57 +0000339 std::string Name("(");
Benjamin Kramere1761952015-10-24 12:46:49 +0000340 for (auto I = Seq.begin(), E = Seq.end(); I != E; ++I) {
Andrew Trick76686492012-09-15 00:19:57 +0000341 if (I != Seq.begin())
342 Name += '_';
343 Name += getSchedRW(*I, IsRead).Name;
344 }
345 Name += ')';
346 return Name;
347}
348
349unsigned CodeGenSchedModels::getSchedRWIdx(Record *Def, bool IsRead,
350 unsigned After) const {
351 const std::vector<CodeGenSchedRW> &RWVec = IsRead ? SchedReads : SchedWrites;
352 assert(After < RWVec.size() && "start position out of bounds");
353 for (std::vector<CodeGenSchedRW>::const_iterator I = RWVec.begin() + After,
354 E = RWVec.end(); I != E; ++I) {
355 if (I->TheDef == Def)
356 return I - RWVec.begin();
357 }
358 return 0;
359}
360
Andrew Trickcfe222c2012-09-19 04:43:19 +0000361bool CodeGenSchedModels::hasReadOfWrite(Record *WriteDef) const {
Javed Absar67b042c2017-09-13 10:31:10 +0000362 for (const CodeGenSchedRW &Read : SchedReads) {
363 Record *ReadDef = Read.TheDef;
Andrew Trickcfe222c2012-09-19 04:43:19 +0000364 if (!ReadDef || !ReadDef->isSubClassOf("ProcReadAdvance"))
365 continue;
366
367 RecVec ValidWrites = ReadDef->getValueAsListOfDefs("ValidWrites");
David Majnemer0d955d02016-08-11 22:21:41 +0000368 if (is_contained(ValidWrites, WriteDef)) {
Andrew Trickcfe222c2012-09-19 04:43:19 +0000369 return true;
370 }
371 }
372 return false;
373}
374
Andrew Trick76686492012-09-15 00:19:57 +0000375namespace llvm {
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +0000376
Andrew Trick76686492012-09-15 00:19:57 +0000377void splitSchedReadWrites(const RecVec &RWDefs,
378 RecVec &WriteDefs, RecVec &ReadDefs) {
Javed Absar67b042c2017-09-13 10:31:10 +0000379 for (Record *RWDef : RWDefs) {
380 if (RWDef->isSubClassOf("SchedWrite"))
381 WriteDefs.push_back(RWDef);
Andrew Trick76686492012-09-15 00:19:57 +0000382 else {
Javed Absar67b042c2017-09-13 10:31:10 +0000383 assert(RWDef->isSubClassOf("SchedRead") && "unknown SchedReadWrite");
384 ReadDefs.push_back(RWDef);
Andrew Trick76686492012-09-15 00:19:57 +0000385 }
386 }
387}
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +0000388
389} // end namespace llvm
Andrew Trick76686492012-09-15 00:19:57 +0000390
391// Split the SchedReadWrites defs and call findRWs for each list.
392void CodeGenSchedModels::findRWs(const RecVec &RWDefs,
393 IdxVec &Writes, IdxVec &Reads) const {
394 RecVec WriteDefs;
395 RecVec ReadDefs;
396 splitSchedReadWrites(RWDefs, WriteDefs, ReadDefs);
397 findRWs(WriteDefs, Writes, false);
398 findRWs(ReadDefs, Reads, true);
399}
400
401// Call getSchedRWIdx for all elements in a sequence of SchedRW defs.
402void CodeGenSchedModels::findRWs(const RecVec &RWDefs, IdxVec &RWs,
403 bool IsRead) const {
Javed Absar67b042c2017-09-13 10:31:10 +0000404 for (Record *RWDef : RWDefs) {
405 unsigned Idx = getSchedRWIdx(RWDef, IsRead);
Andrew Trick76686492012-09-15 00:19:57 +0000406 assert(Idx && "failed to collect SchedReadWrite");
407 RWs.push_back(Idx);
408 }
409}
410
Andrew Trick33401e82012-09-15 00:19:59 +0000411void CodeGenSchedModels::expandRWSequence(unsigned RWIdx, IdxVec &RWSeq,
412 bool IsRead) const {
413 const CodeGenSchedRW &SchedRW = getSchedRW(RWIdx, IsRead);
414 if (!SchedRW.IsSequence) {
415 RWSeq.push_back(RWIdx);
416 return;
417 }
418 int Repeat =
419 SchedRW.TheDef ? SchedRW.TheDef->getValueAsInt("Repeat") : 1;
420 for (int i = 0; i < Repeat; ++i) {
Javed Absar67b042c2017-09-13 10:31:10 +0000421 for (unsigned I : SchedRW.Sequence) {
422 expandRWSequence(I, RWSeq, IsRead);
Andrew Trick33401e82012-09-15 00:19:59 +0000423 }
424 }
425}
426
Andrew Trickda984b12012-10-03 23:06:28 +0000427// Expand a SchedWrite as a sequence following any aliases that coincide with
428// the given processor model.
429void CodeGenSchedModels::expandRWSeqForProc(
430 unsigned RWIdx, IdxVec &RWSeq, bool IsRead,
431 const CodeGenProcModel &ProcModel) const {
432
433 const CodeGenSchedRW &SchedWrite = getSchedRW(RWIdx, IsRead);
Craig Topper24064772014-04-15 07:20:03 +0000434 Record *AliasDef = nullptr;
Andrew Trickda984b12012-10-03 23:06:28 +0000435 for (RecIter AI = SchedWrite.Aliases.begin(), AE = SchedWrite.Aliases.end();
436 AI != AE; ++AI) {
437 const CodeGenSchedRW &AliasRW = getSchedRW((*AI)->getValueAsDef("AliasRW"));
438 if ((*AI)->getValueInit("SchedModel")->isComplete()) {
439 Record *ModelDef = (*AI)->getValueAsDef("SchedModel");
440 if (&getProcModel(ModelDef) != &ProcModel)
441 continue;
442 }
443 if (AliasDef)
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000444 PrintFatalError(AliasRW.TheDef->getLoc(), "Multiple aliases "
445 "defined for processor " + ProcModel.ModelName +
446 " Ensure only one SchedAlias exists per RW.");
Andrew Trickda984b12012-10-03 23:06:28 +0000447 AliasDef = AliasRW.TheDef;
448 }
449 if (AliasDef) {
450 expandRWSeqForProc(getSchedRWIdx(AliasDef, IsRead),
451 RWSeq, IsRead,ProcModel);
452 return;
453 }
454 if (!SchedWrite.IsSequence) {
455 RWSeq.push_back(RWIdx);
456 return;
457 }
458 int Repeat =
459 SchedWrite.TheDef ? SchedWrite.TheDef->getValueAsInt("Repeat") : 1;
460 for (int i = 0; i < Repeat; ++i) {
Javed Absar67b042c2017-09-13 10:31:10 +0000461 for (unsigned I : SchedWrite.Sequence) {
462 expandRWSeqForProc(I, RWSeq, IsRead, ProcModel);
Andrew Trickda984b12012-10-03 23:06:28 +0000463 }
464 }
465}
466
Andrew Trick33401e82012-09-15 00:19:59 +0000467// Find the existing SchedWrite that models this sequence of writes.
Benjamin Kramere1761952015-10-24 12:46:49 +0000468unsigned CodeGenSchedModels::findRWForSequence(ArrayRef<unsigned> Seq,
Andrew Trick33401e82012-09-15 00:19:59 +0000469 bool IsRead) {
470 std::vector<CodeGenSchedRW> &RWVec = IsRead ? SchedReads : SchedWrites;
471
472 for (std::vector<CodeGenSchedRW>::iterator I = RWVec.begin(), E = RWVec.end();
473 I != E; ++I) {
Benjamin Kramere1761952015-10-24 12:46:49 +0000474 if (makeArrayRef(I->Sequence) == Seq)
Andrew Trick33401e82012-09-15 00:19:59 +0000475 return I - RWVec.begin();
476 }
477 // Index zero reserved for invalid RW.
478 return 0;
479}
480
481/// Add this ReadWrite if it doesn't already exist.
482unsigned CodeGenSchedModels::findOrInsertRW(ArrayRef<unsigned> Seq,
483 bool IsRead) {
484 assert(!Seq.empty() && "cannot insert empty sequence");
485 if (Seq.size() == 1)
486 return Seq.back();
487
488 unsigned Idx = findRWForSequence(Seq, IsRead);
489 if (Idx)
490 return Idx;
491
Andrew Trickda984b12012-10-03 23:06:28 +0000492 unsigned RWIdx = IsRead ? SchedReads.size() : SchedWrites.size();
493 CodeGenSchedRW SchedRW(RWIdx, IsRead, Seq, genRWName(Seq, IsRead));
494 if (IsRead)
Andrew Trick33401e82012-09-15 00:19:59 +0000495 SchedReads.push_back(SchedRW);
Andrew Trickda984b12012-10-03 23:06:28 +0000496 else
497 SchedWrites.push_back(SchedRW);
498 return RWIdx;
Andrew Trick33401e82012-09-15 00:19:59 +0000499}
500
Andrew Trick76686492012-09-15 00:19:57 +0000501/// Visit all the instruction definitions for this target to gather and
502/// enumerate the itinerary classes. These are the explicitly specified
503/// SchedClasses. More SchedClasses may be inferred.
504void CodeGenSchedModels::collectSchedClasses() {
505
506 // NoItinerary is always the first class at Idx=0
Andrew Trick87255e32012-07-07 04:00:00 +0000507 SchedClasses.resize(1);
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000508 SchedClasses.back().Index = 0;
509 SchedClasses.back().Name = "NoInstrModel";
510 SchedClasses.back().ItinClassDef = Records.getDef("NoItinerary");
Andrew Trick76686492012-09-15 00:19:57 +0000511 SchedClasses.back().ProcIndices.push_back(0);
Andrew Trick87255e32012-07-07 04:00:00 +0000512
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000513 // Create a SchedClass for each unique combination of itinerary class and
514 // SchedRW list.
Craig Topper8cc904d2016-01-17 20:38:18 +0000515 for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) {
Craig Topper8a417c12014-12-09 08:05:51 +0000516 Record *ItinDef = Inst->TheDef->getValueAsDef("Itinerary");
Andrew Trick76686492012-09-15 00:19:57 +0000517 IdxVec Writes, Reads;
Craig Topper8a417c12014-12-09 08:05:51 +0000518 if (!Inst->TheDef->isValueUnset("SchedRW"))
519 findRWs(Inst->TheDef->getValueAsListOfDefs("SchedRW"), Writes, Reads);
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000520
Andrew Trick76686492012-09-15 00:19:57 +0000521 // ProcIdx == 0 indicates the class applies to all processors.
522 IdxVec ProcIndices(1, 0);
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000523
524 unsigned SCIdx = addSchedClass(ItinDef, Writes, Reads, ProcIndices);
Craig Topper8a417c12014-12-09 08:05:51 +0000525 InstrClassMap[Inst->TheDef] = SCIdx;
Andrew Trick76686492012-09-15 00:19:57 +0000526 }
Andrew Trick9257b8f2012-09-22 02:24:21 +0000527 // Create classes for InstRW defs.
Andrew Trick76686492012-09-15 00:19:57 +0000528 RecVec InstRWDefs = Records.getAllDerivedDefinitions("InstRW");
529 std::sort(InstRWDefs.begin(), InstRWDefs.end(), LessRecord());
Joel Jones80372332017-06-28 00:06:40 +0000530 DEBUG(dbgs() << "\n+++ SCHED CLASSES (createInstRWClass) +++\n");
Javed Absar67b042c2017-09-13 10:31:10 +0000531 for (Record *RWDef : InstRWDefs)
532 createInstRWClass(RWDef);
Andrew Trick87255e32012-07-07 04:00:00 +0000533
Andrew Trick76686492012-09-15 00:19:57 +0000534 NumInstrSchedClasses = SchedClasses.size();
Andrew Trick87255e32012-07-07 04:00:00 +0000535
Andrew Trick76686492012-09-15 00:19:57 +0000536 bool EnableDump = false;
537 DEBUG(EnableDump = true);
538 if (!EnableDump)
Andrew Trick87255e32012-07-07 04:00:00 +0000539 return;
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000540
Joel Jones80372332017-06-28 00:06:40 +0000541 dbgs() << "\n+++ ITINERARIES and/or MACHINE MODELS (collectSchedClasses) +++\n";
Craig Topper8cc904d2016-01-17 20:38:18 +0000542 for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) {
Craig Topperbcd3c372017-05-31 21:12:46 +0000543 StringRef InstName = Inst->TheDef->getName();
Craig Topper8a417c12014-12-09 08:05:51 +0000544 unsigned SCIdx = InstrClassMap.lookup(Inst->TheDef);
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000545 if (!SCIdx) {
Matthias Braun8e0a7342016-03-01 20:03:11 +0000546 if (!Inst->hasNoSchedulingInfo)
547 dbgs() << "No machine model for " << Inst->TheDef->getName() << '\n';
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000548 continue;
549 }
550 CodeGenSchedClass &SC = getSchedClass(SCIdx);
551 if (SC.ProcIndices[0] != 0)
Craig Topper8a417c12014-12-09 08:05:51 +0000552 PrintFatalError(Inst->TheDef->getLoc(), "Instruction's sched class "
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000553 "must not be subtarget specific.");
554
555 IdxVec ProcIndices;
556 if (SC.ItinClassDef->getName() != "NoItinerary") {
557 ProcIndices.push_back(0);
558 dbgs() << "Itinerary for " << InstName << ": "
559 << SC.ItinClassDef->getName() << '\n';
560 }
561 if (!SC.Writes.empty()) {
562 ProcIndices.push_back(0);
563 dbgs() << "SchedRW machine model for " << InstName;
564 for (IdxIter WI = SC.Writes.begin(), WE = SC.Writes.end(); WI != WE; ++WI)
565 dbgs() << " " << SchedWrites[*WI].Name;
566 for (IdxIter RI = SC.Reads.begin(), RE = SC.Reads.end(); RI != RE; ++RI)
567 dbgs() << " " << SchedReads[*RI].Name;
568 dbgs() << '\n';
569 }
570 const RecVec &RWDefs = SchedClasses[SCIdx].InstRWs;
Javed Absar67b042c2017-09-13 10:31:10 +0000571 for (Record *RWDef : RWDefs) {
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000572 const CodeGenProcModel &ProcModel =
Javed Absar67b042c2017-09-13 10:31:10 +0000573 getProcModel(RWDef->getValueAsDef("SchedModel"));
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000574 ProcIndices.push_back(ProcModel.Index);
575 dbgs() << "InstRW on " << ProcModel.ModelName << " for " << InstName;
Andrew Trick76686492012-09-15 00:19:57 +0000576 IdxVec Writes;
577 IdxVec Reads;
Javed Absar67b042c2017-09-13 10:31:10 +0000578 findRWs(RWDef->getValueAsListOfDefs("OperandReadWrites"),
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000579 Writes, Reads);
Javed Absar67b042c2017-09-13 10:31:10 +0000580 for (unsigned WIdx : Writes)
581 dbgs() << " " << SchedWrites[WIdx].Name;
582 for (unsigned RIdx : Reads)
583 dbgs() << " " << SchedReads[RIdx].Name;
Andrew Trick76686492012-09-15 00:19:57 +0000584 dbgs() << '\n';
585 }
Andrew Trickf9df92c92016-10-18 04:17:44 +0000586 // If ProcIndices contains zero, the class applies to all processors.
587 if (!std::count(ProcIndices.begin(), ProcIndices.end(), 0)) {
Javed Absar21c75912017-10-09 16:21:25 +0000588 for (const CodeGenProcModel &PM : ProcModels) {
Javed Absarfc500042017-10-05 13:27:43 +0000589 if (!std::count(ProcIndices.begin(), ProcIndices.end(), PM.Index))
Andrew Trickf9df92c92016-10-18 04:17:44 +0000590 dbgs() << "No machine model for " << Inst->TheDef->getName()
Javed Absarfc500042017-10-05 13:27:43 +0000591 << " on processor " << PM.ModelName << '\n';
Andrew Trickf9df92c92016-10-18 04:17:44 +0000592 }
Andrew Trick87255e32012-07-07 04:00:00 +0000593 }
594 }
Andrew Trick76686492012-09-15 00:19:57 +0000595}
596
Andrew Trick76686492012-09-15 00:19:57 +0000597/// Find an SchedClass that has been inferred from a per-operand list of
598/// SchedWrites and SchedReads.
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000599unsigned CodeGenSchedModels::findSchedClassIdx(Record *ItinClassDef,
Benjamin Kramere1761952015-10-24 12:46:49 +0000600 ArrayRef<unsigned> Writes,
601 ArrayRef<unsigned> Reads) const {
Andrew Trick76686492012-09-15 00:19:57 +0000602 for (SchedClassIter I = schedClassBegin(), E = schedClassEnd(); I != E; ++I) {
Benjamin Kramere1761952015-10-24 12:46:49 +0000603 if (I->ItinClassDef == ItinClassDef && makeArrayRef(I->Writes) == Writes &&
604 makeArrayRef(I->Reads) == Reads) {
Andrew Trick76686492012-09-15 00:19:57 +0000605 return I - schedClassBegin();
606 }
Andrew Trick87255e32012-07-07 04:00:00 +0000607 }
Andrew Trick76686492012-09-15 00:19:57 +0000608 return 0;
609}
Andrew Trick87255e32012-07-07 04:00:00 +0000610
Andrew Trick76686492012-09-15 00:19:57 +0000611// Get the SchedClass index for an instruction.
612unsigned CodeGenSchedModels::getSchedClassIdx(
613 const CodeGenInstruction &Inst) const {
Andrew Trick87255e32012-07-07 04:00:00 +0000614
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000615 return InstrClassMap.lookup(Inst.TheDef);
Andrew Trick76686492012-09-15 00:19:57 +0000616}
617
Benjamin Kramere1761952015-10-24 12:46:49 +0000618std::string
619CodeGenSchedModels::createSchedClassName(Record *ItinClassDef,
620 ArrayRef<unsigned> OperWrites,
621 ArrayRef<unsigned> OperReads) {
Andrew Trick76686492012-09-15 00:19:57 +0000622
623 std::string Name;
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000624 if (ItinClassDef && ItinClassDef->getName() != "NoItinerary")
625 Name = ItinClassDef->getName();
Benjamin Kramere1761952015-10-24 12:46:49 +0000626 for (unsigned Idx : OperWrites) {
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000627 if (!Name.empty())
Andrew Trick76686492012-09-15 00:19:57 +0000628 Name += '_';
Benjamin Kramere1761952015-10-24 12:46:49 +0000629 Name += SchedWrites[Idx].Name;
Andrew Trick76686492012-09-15 00:19:57 +0000630 }
Benjamin Kramere1761952015-10-24 12:46:49 +0000631 for (unsigned Idx : OperReads) {
Andrew Trick76686492012-09-15 00:19:57 +0000632 Name += '_';
Benjamin Kramere1761952015-10-24 12:46:49 +0000633 Name += SchedReads[Idx].Name;
Andrew Trick76686492012-09-15 00:19:57 +0000634 }
635 return Name;
636}
637
638std::string CodeGenSchedModels::createSchedClassName(const RecVec &InstDefs) {
639
640 std::string Name;
641 for (RecIter I = InstDefs.begin(), E = InstDefs.end(); I != E; ++I) {
642 if (I != InstDefs.begin())
643 Name += '_';
644 Name += (*I)->getName();
645 }
646 return Name;
647}
648
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000649/// Add an inferred sched class from an itinerary class and per-operand list of
650/// SchedWrites and SchedReads. ProcIndices contains the set of IDs of
651/// processors that may utilize this class.
652unsigned CodeGenSchedModels::addSchedClass(Record *ItinClassDef,
Benjamin Kramere1761952015-10-24 12:46:49 +0000653 ArrayRef<unsigned> OperWrites,
654 ArrayRef<unsigned> OperReads,
655 ArrayRef<unsigned> ProcIndices) {
Andrew Trick76686492012-09-15 00:19:57 +0000656 assert(!ProcIndices.empty() && "expect at least one ProcIdx");
657
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000658 unsigned Idx = findSchedClassIdx(ItinClassDef, OperWrites, OperReads);
659 if (Idx || SchedClasses[0].isKeyEqual(ItinClassDef, OperWrites, OperReads)) {
Andrew Trick76686492012-09-15 00:19:57 +0000660 IdxVec PI;
661 std::set_union(SchedClasses[Idx].ProcIndices.begin(),
662 SchedClasses[Idx].ProcIndices.end(),
663 ProcIndices.begin(), ProcIndices.end(),
664 std::back_inserter(PI));
665 SchedClasses[Idx].ProcIndices.swap(PI);
666 return Idx;
667 }
668 Idx = SchedClasses.size();
669 SchedClasses.resize(Idx+1);
670 CodeGenSchedClass &SC = SchedClasses.back();
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000671 SC.Index = Idx;
672 SC.Name = createSchedClassName(ItinClassDef, OperWrites, OperReads);
673 SC.ItinClassDef = ItinClassDef;
Andrew Trick76686492012-09-15 00:19:57 +0000674 SC.Writes = OperWrites;
675 SC.Reads = OperReads;
676 SC.ProcIndices = ProcIndices;
677
678 return Idx;
679}
680
681// Create classes for each set of opcodes that are in the same InstReadWrite
682// definition across all processors.
683void CodeGenSchedModels::createInstRWClass(Record *InstRWDef) {
684 // ClassInstrs will hold an entry for each subset of Instrs in InstRWDef that
685 // intersects with an existing class via a previous InstRWDef. Instrs that do
686 // not intersect with an existing class refer back to their former class as
687 // determined from ItinDef or SchedRW.
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +0000688 SmallVector<std::pair<unsigned, SmallVector<Record *, 8>>, 4> ClassInstrs;
Andrew Trick76686492012-09-15 00:19:57 +0000689 // Sort Instrs into sets.
Andrew Trick9e1deb62012-10-03 23:06:32 +0000690 const RecVec *InstDefs = Sets.expand(InstRWDef);
691 if (InstDefs->empty())
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000692 PrintFatalError(InstRWDef->getLoc(), "No matching instruction opcodes");
Andrew Trick9e1deb62012-10-03 23:06:32 +0000693
Javed Absarfc500042017-10-05 13:27:43 +0000694 for (Record *InstDef : make_range(InstDefs->begin(), InstDefs->end())) {
695 InstClassMapTy::const_iterator Pos = InstrClassMap.find(InstDef);
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000696 if (Pos == InstrClassMap.end())
Javed Absarfc500042017-10-05 13:27:43 +0000697 PrintFatalError(InstDef->getLoc(), "No sched class for instruction.");
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000698 unsigned SCIdx = Pos->second;
Andrew Trick76686492012-09-15 00:19:57 +0000699 unsigned CIdx = 0, CEnd = ClassInstrs.size();
700 for (; CIdx != CEnd; ++CIdx) {
701 if (ClassInstrs[CIdx].first == SCIdx)
702 break;
703 }
704 if (CIdx == CEnd) {
705 ClassInstrs.resize(CEnd + 1);
706 ClassInstrs[CIdx].first = SCIdx;
707 }
Javed Absarfc500042017-10-05 13:27:43 +0000708 ClassInstrs[CIdx].second.push_back(InstDef);
Andrew Trick76686492012-09-15 00:19:57 +0000709 }
710 // For each set of Instrs, create a new class if necessary, and map or remap
711 // the Instrs to it.
712 unsigned CIdx = 0, CEnd = ClassInstrs.size();
713 for (; CIdx != CEnd; ++CIdx) {
714 unsigned OldSCIdx = ClassInstrs[CIdx].first;
715 ArrayRef<Record*> InstDefs = ClassInstrs[CIdx].second;
716 // If the all instrs in the current class are accounted for, then leave
717 // them mapped to their old class.
Andrew Trick78a08512013-06-05 06:55:20 +0000718 if (OldSCIdx) {
719 const RecVec &RWDefs = SchedClasses[OldSCIdx].InstRWs;
720 if (!RWDefs.empty()) {
721 const RecVec *OrigInstDefs = Sets.expand(RWDefs[0]);
722 unsigned OrigNumInstrs = 0;
Javed Absar67b042c2017-09-13 10:31:10 +0000723 for (Record *OIDef : make_range(OrigInstDefs->begin(), OrigInstDefs->end())) {
724 if (InstrClassMap[OIDef] == OldSCIdx)
Andrew Trick78a08512013-06-05 06:55:20 +0000725 ++OrigNumInstrs;
726 }
727 if (OrigNumInstrs == InstDefs.size()) {
728 assert(SchedClasses[OldSCIdx].ProcIndices[0] == 0 &&
729 "expected a generic SchedClass");
730 DEBUG(dbgs() << "InstRW: Reuse SC " << OldSCIdx << ":"
731 << SchedClasses[OldSCIdx].Name << " on "
732 << InstRWDef->getValueAsDef("SchedModel")->getName() << "\n");
733 SchedClasses[OldSCIdx].InstRWs.push_back(InstRWDef);
734 continue;
735 }
736 }
Andrew Trick76686492012-09-15 00:19:57 +0000737 }
738 unsigned SCIdx = SchedClasses.size();
739 SchedClasses.resize(SCIdx+1);
740 CodeGenSchedClass &SC = SchedClasses.back();
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000741 SC.Index = SCIdx;
Andrew Trick76686492012-09-15 00:19:57 +0000742 SC.Name = createSchedClassName(InstDefs);
Andrew Trick78a08512013-06-05 06:55:20 +0000743 DEBUG(dbgs() << "InstRW: New SC " << SCIdx << ":" << SC.Name << " on "
744 << InstRWDef->getValueAsDef("SchedModel")->getName() << "\n");
745
Andrew Trick76686492012-09-15 00:19:57 +0000746 // Preserve ItinDef and Writes/Reads for processors without an InstRW entry.
747 SC.ItinClassDef = SchedClasses[OldSCIdx].ItinClassDef;
748 SC.Writes = SchedClasses[OldSCIdx].Writes;
749 SC.Reads = SchedClasses[OldSCIdx].Reads;
750 SC.ProcIndices.push_back(0);
751 // Map each Instr to this new class.
752 // Note that InstDefs may be a smaller list than InstRWDef's "Instrs".
Andrew Trick9e1deb62012-10-03 23:06:32 +0000753 Record *RWModelDef = InstRWDef->getValueAsDef("SchedModel");
754 SmallSet<unsigned, 4> RemappedClassIDs;
Andrew Trick76686492012-09-15 00:19:57 +0000755 for (ArrayRef<Record*>::const_iterator
756 II = InstDefs.begin(), IE = InstDefs.end(); II != IE; ++II) {
757 unsigned OldSCIdx = InstrClassMap[*II];
David Blaikie70573dc2014-11-19 07:49:26 +0000758 if (OldSCIdx && RemappedClassIDs.insert(OldSCIdx).second) {
Andrew Trick9e1deb62012-10-03 23:06:32 +0000759 for (RecIter RI = SchedClasses[OldSCIdx].InstRWs.begin(),
760 RE = SchedClasses[OldSCIdx].InstRWs.end(); RI != RE; ++RI) {
761 if ((*RI)->getValueAsDef("SchedModel") == RWModelDef) {
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000762 PrintFatalError(InstRWDef->getLoc(), "Overlapping InstRW def " +
Andrew Trick9e1deb62012-10-03 23:06:32 +0000763 (*II)->getName() + " also matches " +
764 (*RI)->getValue("Instrs")->getValue()->getAsString());
765 }
766 assert(*RI != InstRWDef && "SchedClass has duplicate InstRW def");
767 SC.InstRWs.push_back(*RI);
768 }
Andrew Trick76686492012-09-15 00:19:57 +0000769 }
770 InstrClassMap[*II] = SCIdx;
771 }
772 SC.InstRWs.push_back(InstRWDef);
773 }
Andrew Trick87255e32012-07-07 04:00:00 +0000774}
775
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000776// True if collectProcItins found anything.
777bool CodeGenSchedModels::hasItineraries() const {
Javed Absar67b042c2017-09-13 10:31:10 +0000778 for (const CodeGenProcModel &PM : make_range(procModelBegin(),procModelEnd())) {
779 if (PM.hasItineraries())
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000780 return true;
781 }
782 return false;
783}
784
Andrew Trick87255e32012-07-07 04:00:00 +0000785// Gather the processor itineraries.
Andrew Trick76686492012-09-15 00:19:57 +0000786void CodeGenSchedModels::collectProcItins() {
Joel Jones80372332017-06-28 00:06:40 +0000787 DEBUG(dbgs() << "\n+++ PROBLEM ITINERARIES (collectProcItins) +++\n");
Craig Topper8a417c12014-12-09 08:05:51 +0000788 for (CodeGenProcModel &ProcModel : ProcModels) {
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000789 if (!ProcModel.hasItineraries())
Andrew Trick87255e32012-07-07 04:00:00 +0000790 continue;
Andrew Trick76686492012-09-15 00:19:57 +0000791
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000792 RecVec ItinRecords = ProcModel.ItinsDef->getValueAsListOfDefs("IID");
793 assert(!ItinRecords.empty() && "ProcModel.hasItineraries is incorrect");
794
795 // Populate ItinDefList with Itinerary records.
796 ProcModel.ItinDefList.resize(NumInstrSchedClasses);
Andrew Trick76686492012-09-15 00:19:57 +0000797
798 // Insert each itinerary data record in the correct position within
799 // the processor model's ItinDefList.
Javed Absarfc500042017-10-05 13:27:43 +0000800 for (Record *ItinData : ItinRecords) {
Andrew Trick76686492012-09-15 00:19:57 +0000801 Record *ItinDef = ItinData->getValueAsDef("TheClass");
Andrew Tricke7bac5f2013-03-18 20:42:25 +0000802 bool FoundClass = false;
803 for (SchedClassIter SCI = schedClassBegin(), SCE = schedClassEnd();
804 SCI != SCE; ++SCI) {
805 // Multiple SchedClasses may share an itinerary. Update all of them.
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000806 if (SCI->ItinClassDef == ItinDef) {
807 ProcModel.ItinDefList[SCI->Index] = ItinData;
Andrew Tricke7bac5f2013-03-18 20:42:25 +0000808 FoundClass = true;
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000809 }
Andrew Trick76686492012-09-15 00:19:57 +0000810 }
Andrew Tricke7bac5f2013-03-18 20:42:25 +0000811 if (!FoundClass) {
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000812 DEBUG(dbgs() << ProcModel.ItinsDef->getName()
813 << " missing class for itinerary " << ItinDef->getName() << '\n');
814 }
Andrew Trick87255e32012-07-07 04:00:00 +0000815 }
Andrew Trick76686492012-09-15 00:19:57 +0000816 // Check for missing itinerary entries.
817 assert(!ProcModel.ItinDefList[0] && "NoItinerary class can't have rec");
818 DEBUG(
819 for (unsigned i = 1, N = ProcModel.ItinDefList.size(); i < N; ++i) {
820 if (!ProcModel.ItinDefList[i])
821 dbgs() << ProcModel.ItinsDef->getName()
822 << " missing itinerary for class "
823 << SchedClasses[i].Name << '\n';
824 });
Andrew Trick87255e32012-07-07 04:00:00 +0000825 }
Andrew Trick87255e32012-07-07 04:00:00 +0000826}
Andrew Trick76686492012-09-15 00:19:57 +0000827
828// Gather the read/write types for each itinerary class.
829void CodeGenSchedModels::collectProcItinRW() {
830 RecVec ItinRWDefs = Records.getAllDerivedDefinitions("ItinRW");
831 std::sort(ItinRWDefs.begin(), ItinRWDefs.end(), LessRecord());
Javed Absar21c75912017-10-09 16:21:25 +0000832 for (Record *RWDef : ItinRWDefs) {
Javed Absarf45d0b92017-10-08 17:23:30 +0000833 if (!RWDef->getValueInit("SchedModel")->isComplete())
834 PrintFatalError(RWDef->getLoc(), "SchedModel is undefined");
835 Record *ModelDef = RWDef->getValueAsDef("SchedModel");
Andrew Trick76686492012-09-15 00:19:57 +0000836 ProcModelMapTy::const_iterator I = ProcModelMap.find(ModelDef);
837 if (I == ProcModelMap.end()) {
Javed Absarf45d0b92017-10-08 17:23:30 +0000838 PrintFatalError(RWDef->getLoc(), "Undefined SchedMachineModel "
Andrew Trick76686492012-09-15 00:19:57 +0000839 + ModelDef->getName());
840 }
Javed Absarf45d0b92017-10-08 17:23:30 +0000841 ProcModels[I->second].ItinRWDefs.push_back(RWDef);
Andrew Trick76686492012-09-15 00:19:57 +0000842 }
843}
844
Simon Dardis5f95c9a2016-06-24 08:43:27 +0000845// Gather the unsupported features for processor models.
846void CodeGenSchedModels::collectProcUnsupportedFeatures() {
847 for (CodeGenProcModel &ProcModel : ProcModels) {
848 for (Record *Pred : ProcModel.ModelDef->getValueAsListOfDefs("UnsupportedFeatures")) {
849 ProcModel.UnsupportedFeaturesDefs.push_back(Pred);
850 }
851 }
852}
853
Andrew Trick33401e82012-09-15 00:19:59 +0000854/// Infer new classes from existing classes. In the process, this may create new
855/// SchedWrites from sequences of existing SchedWrites.
856void CodeGenSchedModels::inferSchedClasses() {
Joel Jones80372332017-06-28 00:06:40 +0000857 DEBUG(dbgs() << "\n+++ INFERRING SCHED CLASSES (inferSchedClasses) +++\n");
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000858 DEBUG(dbgs() << NumInstrSchedClasses << " instr sched classes.\n");
859
Andrew Trick33401e82012-09-15 00:19:59 +0000860 // Visit all existing classes and newly created classes.
861 for (unsigned Idx = 0; Idx != SchedClasses.size(); ++Idx) {
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000862 assert(SchedClasses[Idx].Index == Idx && "bad SCIdx");
863
Andrew Trick33401e82012-09-15 00:19:59 +0000864 if (SchedClasses[Idx].ItinClassDef)
865 inferFromItinClass(SchedClasses[Idx].ItinClassDef, Idx);
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000866 if (!SchedClasses[Idx].InstRWs.empty())
Andrew Trick33401e82012-09-15 00:19:59 +0000867 inferFromInstRWs(Idx);
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000868 if (!SchedClasses[Idx].Writes.empty()) {
Andrew Trick33401e82012-09-15 00:19:59 +0000869 inferFromRW(SchedClasses[Idx].Writes, SchedClasses[Idx].Reads,
870 Idx, SchedClasses[Idx].ProcIndices);
871 }
872 assert(SchedClasses.size() < (NumInstrSchedClasses*6) &&
873 "too many SchedVariants");
874 }
875}
876
877/// Infer classes from per-processor itinerary resources.
878void CodeGenSchedModels::inferFromItinClass(Record *ItinClassDef,
879 unsigned FromClassIdx) {
880 for (unsigned PIdx = 0, PEnd = ProcModels.size(); PIdx != PEnd; ++PIdx) {
881 const CodeGenProcModel &PM = ProcModels[PIdx];
882 // For all ItinRW entries.
883 bool HasMatch = false;
884 for (RecIter II = PM.ItinRWDefs.begin(), IE = PM.ItinRWDefs.end();
885 II != IE; ++II) {
886 RecVec Matched = (*II)->getValueAsListOfDefs("MatchedItinClasses");
887 if (!std::count(Matched.begin(), Matched.end(), ItinClassDef))
888 continue;
889 if (HasMatch)
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000890 PrintFatalError((*II)->getLoc(), "Duplicate itinerary class "
Andrew Trick33401e82012-09-15 00:19:59 +0000891 + ItinClassDef->getName()
892 + " in ItinResources for " + PM.ModelName);
893 HasMatch = true;
894 IdxVec Writes, Reads;
895 findRWs((*II)->getValueAsListOfDefs("OperandReadWrites"), Writes, Reads);
896 IdxVec ProcIndices(1, PIdx);
897 inferFromRW(Writes, Reads, FromClassIdx, ProcIndices);
898 }
899 }
900}
901
902/// Infer classes from per-processor InstReadWrite definitions.
903void CodeGenSchedModels::inferFromInstRWs(unsigned SCIdx) {
Benjamin Kramer58bd79c2013-06-09 15:20:23 +0000904 for (unsigned I = 0, E = SchedClasses[SCIdx].InstRWs.size(); I != E; ++I) {
Benjamin Kramerb22643a2013-06-10 20:19:35 +0000905 assert(SchedClasses[SCIdx].InstRWs.size() == E && "InstrRWs was mutated!");
Benjamin Kramer58bd79c2013-06-09 15:20:23 +0000906 Record *Rec = SchedClasses[SCIdx].InstRWs[I];
907 const RecVec *InstDefs = Sets.expand(Rec);
Andrew Trick9e1deb62012-10-03 23:06:32 +0000908 RecIter II = InstDefs->begin(), IE = InstDefs->end();
Andrew Trick33401e82012-09-15 00:19:59 +0000909 for (; II != IE; ++II) {
910 if (InstrClassMap[*II] == SCIdx)
911 break;
912 }
913 // If this class no longer has any instructions mapped to it, it has become
914 // irrelevant.
915 if (II == IE)
916 continue;
917 IdxVec Writes, Reads;
Benjamin Kramer58bd79c2013-06-09 15:20:23 +0000918 findRWs(Rec->getValueAsListOfDefs("OperandReadWrites"), Writes, Reads);
919 unsigned PIdx = getProcModel(Rec->getValueAsDef("SchedModel")).Index;
Andrew Trick33401e82012-09-15 00:19:59 +0000920 IdxVec ProcIndices(1, PIdx);
Benjamin Kramer58bd79c2013-06-09 15:20:23 +0000921 inferFromRW(Writes, Reads, SCIdx, ProcIndices); // May mutate SchedClasses.
Andrew Trick33401e82012-09-15 00:19:59 +0000922 }
923}
924
925namespace {
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +0000926
Andrew Trick9257b8f2012-09-22 02:24:21 +0000927// Helper for substituteVariantOperand.
928struct TransVariant {
Andrew Trickda984b12012-10-03 23:06:28 +0000929 Record *VarOrSeqDef; // Variant or sequence.
930 unsigned RWIdx; // Index of this variant or sequence's matched type.
Andrew Trick9257b8f2012-09-22 02:24:21 +0000931 unsigned ProcIdx; // Processor model index or zero for any.
932 unsigned TransVecIdx; // Index into PredTransitions::TransVec.
933
934 TransVariant(Record *def, unsigned rwi, unsigned pi, unsigned ti):
Andrew Trickda984b12012-10-03 23:06:28 +0000935 VarOrSeqDef(def), RWIdx(rwi), ProcIdx(pi), TransVecIdx(ti) {}
Andrew Trick9257b8f2012-09-22 02:24:21 +0000936};
937
Andrew Trick33401e82012-09-15 00:19:59 +0000938// Associate a predicate with the SchedReadWrite that it guards.
939// RWIdx is the index of the read/write variant.
940struct PredCheck {
941 bool IsRead;
942 unsigned RWIdx;
943 Record *Predicate;
944
945 PredCheck(bool r, unsigned w, Record *p): IsRead(r), RWIdx(w), Predicate(p) {}
946};
947
948// A Predicate transition is a list of RW sequences guarded by a PredTerm.
949struct PredTransition {
950 // A predicate term is a conjunction of PredChecks.
951 SmallVector<PredCheck, 4> PredTerm;
952 SmallVector<SmallVector<unsigned,4>, 16> WriteSequences;
953 SmallVector<SmallVector<unsigned,4>, 16> ReadSequences;
Andrew Trick9257b8f2012-09-22 02:24:21 +0000954 SmallVector<unsigned, 4> ProcIndices;
Andrew Trick33401e82012-09-15 00:19:59 +0000955};
956
957// Encapsulate a set of partially constructed transitions.
958// The results are built by repeated calls to substituteVariants.
959class PredTransitions {
960 CodeGenSchedModels &SchedModels;
961
962public:
963 std::vector<PredTransition> TransVec;
964
965 PredTransitions(CodeGenSchedModels &sm): SchedModels(sm) {}
966
967 void substituteVariantOperand(const SmallVectorImpl<unsigned> &RWSeq,
968 bool IsRead, unsigned StartIdx);
969
970 void substituteVariants(const PredTransition &Trans);
971
972#ifndef NDEBUG
973 void dump() const;
974#endif
975
976private:
977 bool mutuallyExclusive(Record *PredDef, ArrayRef<PredCheck> Term);
Andrew Trickda984b12012-10-03 23:06:28 +0000978 void getIntersectingVariants(
979 const CodeGenSchedRW &SchedRW, unsigned TransIdx,
980 std::vector<TransVariant> &IntersectingVariants);
Andrew Trick9257b8f2012-09-22 02:24:21 +0000981 void pushVariant(const TransVariant &VInfo, bool IsRead);
Andrew Trick33401e82012-09-15 00:19:59 +0000982};
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +0000983
984} // end anonymous namespace
Andrew Trick33401e82012-09-15 00:19:59 +0000985
986// Return true if this predicate is mutually exclusive with a PredTerm. This
987// degenerates into checking if the predicate is mutually exclusive with any
988// predicate in the Term's conjunction.
989//
990// All predicates associated with a given SchedRW are considered mutually
991// exclusive. This should work even if the conditions expressed by the
992// predicates are not exclusive because the predicates for a given SchedWrite
993// are always checked in the order they are defined in the .td file. Later
994// conditions implicitly negate any prior condition.
995bool PredTransitions::mutuallyExclusive(Record *PredDef,
996 ArrayRef<PredCheck> Term) {
Javed Absar21c75912017-10-09 16:21:25 +0000997 for (const PredCheck &PC: Term) {
Javed Absarfc500042017-10-05 13:27:43 +0000998 if (PC.Predicate == PredDef)
Andrew Trick33401e82012-09-15 00:19:59 +0000999 return false;
1000
Javed Absarfc500042017-10-05 13:27:43 +00001001 const CodeGenSchedRW &SchedRW = SchedModels.getSchedRW(PC.RWIdx, PC.IsRead);
Andrew Trick33401e82012-09-15 00:19:59 +00001002 assert(SchedRW.HasVariants && "PredCheck must refer to a SchedVariant");
1003 RecVec Variants = SchedRW.TheDef->getValueAsListOfDefs("Variants");
1004 for (RecIter VI = Variants.begin(), VE = Variants.end(); VI != VE; ++VI) {
1005 if ((*VI)->getValueAsDef("Predicate") == PredDef)
1006 return true;
1007 }
1008 }
1009 return false;
1010}
1011
Andrew Trickda984b12012-10-03 23:06:28 +00001012static bool hasAliasedVariants(const CodeGenSchedRW &RW,
1013 CodeGenSchedModels &SchedModels) {
1014 if (RW.HasVariants)
1015 return true;
1016
Javed Absar21c75912017-10-09 16:21:25 +00001017 for (Record *Alias : RW.Aliases) {
Andrew Trickda984b12012-10-03 23:06:28 +00001018 const CodeGenSchedRW &AliasRW =
Javed Absarfc500042017-10-05 13:27:43 +00001019 SchedModels.getSchedRW(Alias->getValueAsDef("AliasRW"));
Andrew Trickda984b12012-10-03 23:06:28 +00001020 if (AliasRW.HasVariants)
1021 return true;
1022 if (AliasRW.IsSequence) {
1023 IdxVec ExpandedRWs;
1024 SchedModels.expandRWSequence(AliasRW.Index, ExpandedRWs, AliasRW.IsRead);
1025 for (IdxIter SI = ExpandedRWs.begin(), SE = ExpandedRWs.end();
1026 SI != SE; ++SI) {
1027 if (hasAliasedVariants(SchedModels.getSchedRW(*SI, AliasRW.IsRead),
1028 SchedModels)) {
1029 return true;
1030 }
1031 }
1032 }
1033 }
1034 return false;
1035}
1036
1037static bool hasVariant(ArrayRef<PredTransition> Transitions,
1038 CodeGenSchedModels &SchedModels) {
1039 for (ArrayRef<PredTransition>::iterator
1040 PTI = Transitions.begin(), PTE = Transitions.end();
1041 PTI != PTE; ++PTI) {
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +00001042 for (SmallVectorImpl<SmallVector<unsigned,4>>::const_iterator
Andrew Trickda984b12012-10-03 23:06:28 +00001043 WSI = PTI->WriteSequences.begin(), WSE = PTI->WriteSequences.end();
1044 WSI != WSE; ++WSI) {
1045 for (SmallVectorImpl<unsigned>::const_iterator
1046 WI = WSI->begin(), WE = WSI->end(); WI != WE; ++WI) {
1047 if (hasAliasedVariants(SchedModels.getSchedWrite(*WI), SchedModels))
1048 return true;
1049 }
1050 }
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +00001051 for (SmallVectorImpl<SmallVector<unsigned,4>>::const_iterator
Andrew Trickda984b12012-10-03 23:06:28 +00001052 RSI = PTI->ReadSequences.begin(), RSE = PTI->ReadSequences.end();
1053 RSI != RSE; ++RSI) {
1054 for (SmallVectorImpl<unsigned>::const_iterator
1055 RI = RSI->begin(), RE = RSI->end(); RI != RE; ++RI) {
1056 if (hasAliasedVariants(SchedModels.getSchedRead(*RI), SchedModels))
1057 return true;
1058 }
1059 }
1060 }
1061 return false;
1062}
1063
1064// Populate IntersectingVariants with any variants or aliased sequences of the
1065// given SchedRW whose processor indices and predicates are not mutually
Andrew Trickd97ff1f2013-03-29 19:08:31 +00001066// exclusive with the given transition.
Andrew Trickda984b12012-10-03 23:06:28 +00001067void PredTransitions::getIntersectingVariants(
1068 const CodeGenSchedRW &SchedRW, unsigned TransIdx,
1069 std::vector<TransVariant> &IntersectingVariants) {
1070
Andrew Trickd97ff1f2013-03-29 19:08:31 +00001071 bool GenericRW = false;
1072
Andrew Trickda984b12012-10-03 23:06:28 +00001073 std::vector<TransVariant> Variants;
1074 if (SchedRW.HasVariants) {
1075 unsigned VarProcIdx = 0;
1076 if (SchedRW.TheDef->getValueInit("SchedModel")->isComplete()) {
1077 Record *ModelDef = SchedRW.TheDef->getValueAsDef("SchedModel");
1078 VarProcIdx = SchedModels.getProcModel(ModelDef).Index;
1079 }
1080 // Push each variant. Assign TransVecIdx later.
1081 const RecVec VarDefs = SchedRW.TheDef->getValueAsListOfDefs("Variants");
Javed Absarf45d0b92017-10-08 17:23:30 +00001082 for (Record *VarDef : VarDefs)
1083 Variants.push_back(TransVariant(VarDef, SchedRW.Index, VarProcIdx, 0));
Andrew Trickd97ff1f2013-03-29 19:08:31 +00001084 if (VarProcIdx == 0)
1085 GenericRW = true;
Andrew Trickda984b12012-10-03 23:06:28 +00001086 }
1087 for (RecIter AI = SchedRW.Aliases.begin(), AE = SchedRW.Aliases.end();
1088 AI != AE; ++AI) {
1089 // If either the SchedAlias itself or the SchedReadWrite that it aliases
1090 // to is defined within a processor model, constrain all variants to
1091 // that processor.
1092 unsigned AliasProcIdx = 0;
1093 if ((*AI)->getValueInit("SchedModel")->isComplete()) {
1094 Record *ModelDef = (*AI)->getValueAsDef("SchedModel");
1095 AliasProcIdx = SchedModels.getProcModel(ModelDef).Index;
1096 }
1097 const CodeGenSchedRW &AliasRW =
1098 SchedModels.getSchedRW((*AI)->getValueAsDef("AliasRW"));
1099
1100 if (AliasRW.HasVariants) {
1101 const RecVec VarDefs = AliasRW.TheDef->getValueAsListOfDefs("Variants");
Javed Absar9003dd72017-10-10 15:58:45 +00001102 for (Record *VD : VarDefs)
1103 Variants.push_back(TransVariant(VD, AliasRW.Index, AliasProcIdx, 0));
Andrew Trickda984b12012-10-03 23:06:28 +00001104 }
1105 if (AliasRW.IsSequence) {
1106 Variants.push_back(
1107 TransVariant(AliasRW.TheDef, SchedRW.Index, AliasProcIdx, 0));
1108 }
Andrew Trickd97ff1f2013-03-29 19:08:31 +00001109 if (AliasProcIdx == 0)
1110 GenericRW = true;
Andrew Trickda984b12012-10-03 23:06:28 +00001111 }
Javed Absarf45d0b92017-10-08 17:23:30 +00001112 for (TransVariant &Variant : Variants) {
Andrew Trickda984b12012-10-03 23:06:28 +00001113 // Don't expand variants if the processor models don't intersect.
1114 // A zero processor index means any processor.
Craig Topperb94011f2013-07-14 04:42:23 +00001115 SmallVectorImpl<unsigned> &ProcIndices = TransVec[TransIdx].ProcIndices;
Javed Absarf45d0b92017-10-08 17:23:30 +00001116 if (ProcIndices[0] && Variant.ProcIdx) {
Andrew Trickda984b12012-10-03 23:06:28 +00001117 unsigned Cnt = std::count(ProcIndices.begin(), ProcIndices.end(),
1118 Variant.ProcIdx);
1119 if (!Cnt)
1120 continue;
1121 if (Cnt > 1) {
1122 const CodeGenProcModel &PM =
1123 *(SchedModels.procModelBegin() + Variant.ProcIdx);
Joerg Sonnenberger635debe2012-10-25 20:33:17 +00001124 PrintFatalError(Variant.VarOrSeqDef->getLoc(),
1125 "Multiple variants defined for processor " +
1126 PM.ModelName +
1127 " Ensure only one SchedAlias exists per RW.");
Andrew Trickda984b12012-10-03 23:06:28 +00001128 }
1129 }
1130 if (Variant.VarOrSeqDef->isSubClassOf("SchedVar")) {
1131 Record *PredDef = Variant.VarOrSeqDef->getValueAsDef("Predicate");
1132 if (mutuallyExclusive(PredDef, TransVec[TransIdx].PredTerm))
1133 continue;
1134 }
1135 if (IntersectingVariants.empty()) {
1136 // The first variant builds on the existing transition.
1137 Variant.TransVecIdx = TransIdx;
1138 IntersectingVariants.push_back(Variant);
1139 }
1140 else {
1141 // Push another copy of the current transition for more variants.
1142 Variant.TransVecIdx = TransVec.size();
1143 IntersectingVariants.push_back(Variant);
Dan Gohmanf6169d02013-03-29 00:13:08 +00001144 TransVec.push_back(TransVec[TransIdx]);
Andrew Trickda984b12012-10-03 23:06:28 +00001145 }
1146 }
Andrew Trickd97ff1f2013-03-29 19:08:31 +00001147 if (GenericRW && IntersectingVariants.empty()) {
1148 PrintFatalError(SchedRW.TheDef->getLoc(), "No variant of this type has "
1149 "a matching predicate on any processor");
1150 }
Andrew Trickda984b12012-10-03 23:06:28 +00001151}
1152
Andrew Trick9257b8f2012-09-22 02:24:21 +00001153// Push the Reads/Writes selected by this variant onto the PredTransition
1154// specified by VInfo.
1155void PredTransitions::
1156pushVariant(const TransVariant &VInfo, bool IsRead) {
Andrew Trick9257b8f2012-09-22 02:24:21 +00001157 PredTransition &Trans = TransVec[VInfo.TransVecIdx];
1158
Andrew Trick9257b8f2012-09-22 02:24:21 +00001159 // If this operand transition is reached through a processor-specific alias,
1160 // then the whole transition is specific to this processor.
1161 if (VInfo.ProcIdx != 0)
1162 Trans.ProcIndices.assign(1, VInfo.ProcIdx);
1163
Andrew Trick33401e82012-09-15 00:19:59 +00001164 IdxVec SelectedRWs;
Andrew Trickda984b12012-10-03 23:06:28 +00001165 if (VInfo.VarOrSeqDef->isSubClassOf("SchedVar")) {
1166 Record *PredDef = VInfo.VarOrSeqDef->getValueAsDef("Predicate");
1167 Trans.PredTerm.push_back(PredCheck(IsRead, VInfo.RWIdx,PredDef));
1168 RecVec SelectedDefs = VInfo.VarOrSeqDef->getValueAsListOfDefs("Selected");
1169 SchedModels.findRWs(SelectedDefs, SelectedRWs, IsRead);
1170 }
1171 else {
1172 assert(VInfo.VarOrSeqDef->isSubClassOf("WriteSequence") &&
1173 "variant must be a SchedVariant or aliased WriteSequence");
1174 SelectedRWs.push_back(SchedModels.getSchedRWIdx(VInfo.VarOrSeqDef, IsRead));
1175 }
Andrew Trick33401e82012-09-15 00:19:59 +00001176
Andrew Trick9257b8f2012-09-22 02:24:21 +00001177 const CodeGenSchedRW &SchedRW = SchedModels.getSchedRW(VInfo.RWIdx, IsRead);
Andrew Trick33401e82012-09-15 00:19:59 +00001178
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +00001179 SmallVectorImpl<SmallVector<unsigned,4>> &RWSequences = IsRead
Andrew Trick33401e82012-09-15 00:19:59 +00001180 ? Trans.ReadSequences : Trans.WriteSequences;
1181 if (SchedRW.IsVariadic) {
1182 unsigned OperIdx = RWSequences.size()-1;
1183 // Make N-1 copies of this transition's last sequence.
1184 for (unsigned i = 1, e = SelectedRWs.size(); i != e; ++i) {
Arnold Schwaighofer3bd25242013-06-06 23:23:14 +00001185 // Create a temporary copy the vector could reallocate.
Arnold Schwaighoferf84a03a2013-06-07 00:04:30 +00001186 RWSequences.reserve(RWSequences.size() + 1);
1187 RWSequences.push_back(RWSequences[OperIdx]);
Andrew Trick33401e82012-09-15 00:19:59 +00001188 }
1189 // Push each of the N elements of the SelectedRWs onto a copy of the last
1190 // sequence (split the current operand into N operands).
1191 // Note that write sequences should be expanded within this loop--the entire
1192 // sequence belongs to a single operand.
1193 for (IdxIter RWI = SelectedRWs.begin(), RWE = SelectedRWs.end();
1194 RWI != RWE; ++RWI, ++OperIdx) {
1195 IdxVec ExpandedRWs;
1196 if (IsRead)
1197 ExpandedRWs.push_back(*RWI);
1198 else
1199 SchedModels.expandRWSequence(*RWI, ExpandedRWs, IsRead);
1200 RWSequences[OperIdx].insert(RWSequences[OperIdx].end(),
1201 ExpandedRWs.begin(), ExpandedRWs.end());
1202 }
1203 assert(OperIdx == RWSequences.size() && "missed a sequence");
1204 }
1205 else {
1206 // Push this transition's expanded sequence onto this transition's last
1207 // sequence (add to the current operand's sequence).
1208 SmallVectorImpl<unsigned> &Seq = RWSequences.back();
1209 IdxVec ExpandedRWs;
1210 for (IdxIter RWI = SelectedRWs.begin(), RWE = SelectedRWs.end();
1211 RWI != RWE; ++RWI) {
1212 if (IsRead)
1213 ExpandedRWs.push_back(*RWI);
1214 else
1215 SchedModels.expandRWSequence(*RWI, ExpandedRWs, IsRead);
1216 }
1217 Seq.insert(Seq.end(), ExpandedRWs.begin(), ExpandedRWs.end());
1218 }
1219}
1220
1221// RWSeq is a sequence of all Reads or all Writes for the next read or write
1222// operand. StartIdx is an index into TransVec where partial results
Andrew Trick9257b8f2012-09-22 02:24:21 +00001223// starts. RWSeq must be applied to all transitions between StartIdx and the end
Andrew Trick33401e82012-09-15 00:19:59 +00001224// of TransVec.
1225void PredTransitions::substituteVariantOperand(
1226 const SmallVectorImpl<unsigned> &RWSeq, bool IsRead, unsigned StartIdx) {
1227
1228 // Visit each original RW within the current sequence.
1229 for (SmallVectorImpl<unsigned>::const_iterator
1230 RWI = RWSeq.begin(), RWE = RWSeq.end(); RWI != RWE; ++RWI) {
1231 const CodeGenSchedRW &SchedRW = SchedModels.getSchedRW(*RWI, IsRead);
1232 // Push this RW on all partial PredTransitions or distribute variants.
1233 // New PredTransitions may be pushed within this loop which should not be
1234 // revisited (TransEnd must be loop invariant).
1235 for (unsigned TransIdx = StartIdx, TransEnd = TransVec.size();
1236 TransIdx != TransEnd; ++TransIdx) {
1237 // In the common case, push RW onto the current operand's sequence.
Andrew Trick9257b8f2012-09-22 02:24:21 +00001238 if (!hasAliasedVariants(SchedRW, SchedModels)) {
Andrew Trick33401e82012-09-15 00:19:59 +00001239 if (IsRead)
1240 TransVec[TransIdx].ReadSequences.back().push_back(*RWI);
1241 else
1242 TransVec[TransIdx].WriteSequences.back().push_back(*RWI);
1243 continue;
1244 }
1245 // Distribute this partial PredTransition across intersecting variants.
Andrew Trickda984b12012-10-03 23:06:28 +00001246 // This will push a copies of TransVec[TransIdx] on the back of TransVec.
Andrew Trick9257b8f2012-09-22 02:24:21 +00001247 std::vector<TransVariant> IntersectingVariants;
Andrew Trickda984b12012-10-03 23:06:28 +00001248 getIntersectingVariants(SchedRW, TransIdx, IntersectingVariants);
Andrew Trick33401e82012-09-15 00:19:59 +00001249 // Now expand each variant on top of its copy of the transition.
Andrew Trick9257b8f2012-09-22 02:24:21 +00001250 for (std::vector<TransVariant>::const_iterator
Andrew Trick33401e82012-09-15 00:19:59 +00001251 IVI = IntersectingVariants.begin(),
1252 IVE = IntersectingVariants.end();
Andrew Trick9257b8f2012-09-22 02:24:21 +00001253 IVI != IVE; ++IVI) {
1254 pushVariant(*IVI, IsRead);
1255 }
Andrew Trick33401e82012-09-15 00:19:59 +00001256 }
1257 }
1258}
1259
1260// For each variant of a Read/Write in Trans, substitute the sequence of
1261// Read/Writes guarded by the variant. This is exponential in the number of
1262// variant Read/Writes, but in practice detection of mutually exclusive
1263// predicates should result in linear growth in the total number variants.
1264//
1265// This is one step in a breadth-first search of nested variants.
1266void PredTransitions::substituteVariants(const PredTransition &Trans) {
1267 // Build up a set of partial results starting at the back of
1268 // PredTransitions. Remember the first new transition.
1269 unsigned StartIdx = TransVec.size();
1270 TransVec.resize(TransVec.size() + 1);
1271 TransVec.back().PredTerm = Trans.PredTerm;
Andrew Trick9257b8f2012-09-22 02:24:21 +00001272 TransVec.back().ProcIndices = Trans.ProcIndices;
Andrew Trick33401e82012-09-15 00:19:59 +00001273
1274 // Visit each original write sequence.
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +00001275 for (SmallVectorImpl<SmallVector<unsigned,4>>::const_iterator
Andrew Trick33401e82012-09-15 00:19:59 +00001276 WSI = Trans.WriteSequences.begin(), WSE = Trans.WriteSequences.end();
1277 WSI != WSE; ++WSI) {
1278 // Push a new (empty) write sequence onto all partial Transitions.
1279 for (std::vector<PredTransition>::iterator I =
1280 TransVec.begin() + StartIdx, E = TransVec.end(); I != E; ++I) {
1281 I->WriteSequences.resize(I->WriteSequences.size() + 1);
1282 }
1283 substituteVariantOperand(*WSI, /*IsRead=*/false, StartIdx);
1284 }
1285 // Visit each original read sequence.
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +00001286 for (SmallVectorImpl<SmallVector<unsigned,4>>::const_iterator
Andrew Trick33401e82012-09-15 00:19:59 +00001287 RSI = Trans.ReadSequences.begin(), RSE = Trans.ReadSequences.end();
1288 RSI != RSE; ++RSI) {
1289 // Push a new (empty) read sequence onto all partial Transitions.
1290 for (std::vector<PredTransition>::iterator I =
1291 TransVec.begin() + StartIdx, E = TransVec.end(); I != E; ++I) {
1292 I->ReadSequences.resize(I->ReadSequences.size() + 1);
1293 }
1294 substituteVariantOperand(*RSI, /*IsRead=*/true, StartIdx);
1295 }
1296}
1297
Andrew Trick33401e82012-09-15 00:19:59 +00001298// Create a new SchedClass for each variant found by inferFromRW. Pass
Andrew Trick33401e82012-09-15 00:19:59 +00001299static void inferFromTransitions(ArrayRef<PredTransition> LastTransitions,
Andrew Trick9257b8f2012-09-22 02:24:21 +00001300 unsigned FromClassIdx,
Andrew Trick33401e82012-09-15 00:19:59 +00001301 CodeGenSchedModels &SchedModels) {
1302 // For each PredTransition, create a new CodeGenSchedTransition, which usually
1303 // requires creating a new SchedClass.
1304 for (ArrayRef<PredTransition>::iterator
1305 I = LastTransitions.begin(), E = LastTransitions.end(); I != E; ++I) {
1306 IdxVec OperWritesVariant;
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +00001307 for (SmallVectorImpl<SmallVector<unsigned,4>>::const_iterator
Andrew Trick33401e82012-09-15 00:19:59 +00001308 WSI = I->WriteSequences.begin(), WSE = I->WriteSequences.end();
1309 WSI != WSE; ++WSI) {
1310 // Create a new write representing the expanded sequence.
1311 OperWritesVariant.push_back(
1312 SchedModels.findOrInsertRW(*WSI, /*IsRead=*/false));
1313 }
1314 IdxVec OperReadsVariant;
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +00001315 for (SmallVectorImpl<SmallVector<unsigned,4>>::const_iterator
Andrew Trick33401e82012-09-15 00:19:59 +00001316 RSI = I->ReadSequences.begin(), RSE = I->ReadSequences.end();
1317 RSI != RSE; ++RSI) {
Andrew Trick9257b8f2012-09-22 02:24:21 +00001318 // Create a new read representing the expanded sequence.
Andrew Trick33401e82012-09-15 00:19:59 +00001319 OperReadsVariant.push_back(
1320 SchedModels.findOrInsertRW(*RSI, /*IsRead=*/true));
1321 }
Andrew Trick9257b8f2012-09-22 02:24:21 +00001322 IdxVec ProcIndices(I->ProcIndices.begin(), I->ProcIndices.end());
Andrew Trick33401e82012-09-15 00:19:59 +00001323 CodeGenSchedTransition SCTrans;
1324 SCTrans.ToClassIdx =
Craig Topper24064772014-04-15 07:20:03 +00001325 SchedModels.addSchedClass(/*ItinClassDef=*/nullptr, OperWritesVariant,
Andrew Trickbf8a28d2013-03-16 18:58:55 +00001326 OperReadsVariant, ProcIndices);
Andrew Trick33401e82012-09-15 00:19:59 +00001327 SCTrans.ProcIndices = ProcIndices;
1328 // The final PredTerm is unique set of predicates guarding the transition.
1329 RecVec Preds;
1330 for (SmallVectorImpl<PredCheck>::const_iterator
1331 PI = I->PredTerm.begin(), PE = I->PredTerm.end(); PI != PE; ++PI) {
1332 Preds.push_back(PI->Predicate);
1333 }
1334 RecIter PredsEnd = std::unique(Preds.begin(), Preds.end());
1335 Preds.resize(PredsEnd - Preds.begin());
1336 SCTrans.PredTerm = Preds;
1337 SchedModels.getSchedClass(FromClassIdx).Transitions.push_back(SCTrans);
1338 }
1339}
1340
Andrew Trick9257b8f2012-09-22 02:24:21 +00001341// Create new SchedClasses for the given ReadWrite list. If any of the
1342// ReadWrites refers to a SchedVariant, create a new SchedClass for each variant
1343// of the ReadWrite list, following Aliases if necessary.
Benjamin Kramere1761952015-10-24 12:46:49 +00001344void CodeGenSchedModels::inferFromRW(ArrayRef<unsigned> OperWrites,
1345 ArrayRef<unsigned> OperReads,
Andrew Trick33401e82012-09-15 00:19:59 +00001346 unsigned FromClassIdx,
Benjamin Kramere1761952015-10-24 12:46:49 +00001347 ArrayRef<unsigned> ProcIndices) {
Andrew Tricke97978f2013-03-26 21:36:39 +00001348 DEBUG(dbgs() << "INFER RW proc("; dumpIdxVec(ProcIndices); dbgs() << ") ");
Andrew Trick33401e82012-09-15 00:19:59 +00001349
1350 // Create a seed transition with an empty PredTerm and the expanded sequences
1351 // of SchedWrites for the current SchedClass.
1352 std::vector<PredTransition> LastTransitions;
1353 LastTransitions.resize(1);
Andrew Trick9257b8f2012-09-22 02:24:21 +00001354 LastTransitions.back().ProcIndices.append(ProcIndices.begin(),
1355 ProcIndices.end());
1356
Benjamin Kramere1761952015-10-24 12:46:49 +00001357 for (unsigned WriteIdx : OperWrites) {
Andrew Trick33401e82012-09-15 00:19:59 +00001358 IdxVec WriteSeq;
Benjamin Kramere1761952015-10-24 12:46:49 +00001359 expandRWSequence(WriteIdx, WriteSeq, /*IsRead=*/false);
Andrew Trick33401e82012-09-15 00:19:59 +00001360 unsigned Idx = LastTransitions[0].WriteSequences.size();
1361 LastTransitions[0].WriteSequences.resize(Idx + 1);
1362 SmallVectorImpl<unsigned> &Seq = LastTransitions[0].WriteSequences[Idx];
1363 for (IdxIter WI = WriteSeq.begin(), WE = WriteSeq.end(); WI != WE; ++WI)
1364 Seq.push_back(*WI);
1365 DEBUG(dbgs() << "("; dumpIdxVec(Seq); dbgs() << ") ");
1366 }
1367 DEBUG(dbgs() << " Reads: ");
Benjamin Kramere1761952015-10-24 12:46:49 +00001368 for (unsigned ReadIdx : OperReads) {
Andrew Trick33401e82012-09-15 00:19:59 +00001369 IdxVec ReadSeq;
Benjamin Kramere1761952015-10-24 12:46:49 +00001370 expandRWSequence(ReadIdx, ReadSeq, /*IsRead=*/true);
Andrew Trick33401e82012-09-15 00:19:59 +00001371 unsigned Idx = LastTransitions[0].ReadSequences.size();
1372 LastTransitions[0].ReadSequences.resize(Idx + 1);
1373 SmallVectorImpl<unsigned> &Seq = LastTransitions[0].ReadSequences[Idx];
1374 for (IdxIter RI = ReadSeq.begin(), RE = ReadSeq.end(); RI != RE; ++RI)
1375 Seq.push_back(*RI);
1376 DEBUG(dbgs() << "("; dumpIdxVec(Seq); dbgs() << ") ");
1377 }
1378 DEBUG(dbgs() << '\n');
1379
1380 // Collect all PredTransitions for individual operands.
1381 // Iterate until no variant writes remain.
1382 while (hasVariant(LastTransitions, *this)) {
1383 PredTransitions Transitions(*this);
1384 for (std::vector<PredTransition>::const_iterator
1385 I = LastTransitions.begin(), E = LastTransitions.end();
1386 I != E; ++I) {
1387 Transitions.substituteVariants(*I);
1388 }
1389 DEBUG(Transitions.dump());
1390 LastTransitions.swap(Transitions.TransVec);
1391 }
1392 // If the first transition has no variants, nothing to do.
1393 if (LastTransitions[0].PredTerm.empty())
1394 return;
1395
1396 // WARNING: We are about to mutate the SchedClasses vector. Do not refer to
1397 // OperWrites, OperReads, or ProcIndices after calling inferFromTransitions.
Andrew Trick9257b8f2012-09-22 02:24:21 +00001398 inferFromTransitions(LastTransitions, FromClassIdx, *this);
Andrew Trick33401e82012-09-15 00:19:59 +00001399}
1400
Andrew Trickcf398b22013-04-23 23:45:14 +00001401// Check if any processor resource group contains all resource records in
1402// SubUnits.
1403bool CodeGenSchedModels::hasSuperGroup(RecVec &SubUnits, CodeGenProcModel &PM) {
1404 for (unsigned i = 0, e = PM.ProcResourceDefs.size(); i < e; ++i) {
1405 if (!PM.ProcResourceDefs[i]->isSubClassOf("ProcResGroup"))
1406 continue;
1407 RecVec SuperUnits =
1408 PM.ProcResourceDefs[i]->getValueAsListOfDefs("Resources");
1409 RecIter RI = SubUnits.begin(), RE = SubUnits.end();
1410 for ( ; RI != RE; ++RI) {
David Majnemer0d955d02016-08-11 22:21:41 +00001411 if (!is_contained(SuperUnits, *RI)) {
Andrew Trickcf398b22013-04-23 23:45:14 +00001412 break;
1413 }
1414 }
1415 if (RI == RE)
1416 return true;
1417 }
1418 return false;
1419}
1420
1421// Verify that overlapping groups have a common supergroup.
1422void CodeGenSchedModels::verifyProcResourceGroups(CodeGenProcModel &PM) {
1423 for (unsigned i = 0, e = PM.ProcResourceDefs.size(); i < e; ++i) {
1424 if (!PM.ProcResourceDefs[i]->isSubClassOf("ProcResGroup"))
1425 continue;
1426 RecVec CheckUnits =
1427 PM.ProcResourceDefs[i]->getValueAsListOfDefs("Resources");
1428 for (unsigned j = i+1; j < e; ++j) {
1429 if (!PM.ProcResourceDefs[j]->isSubClassOf("ProcResGroup"))
1430 continue;
1431 RecVec OtherUnits =
1432 PM.ProcResourceDefs[j]->getValueAsListOfDefs("Resources");
1433 if (std::find_first_of(CheckUnits.begin(), CheckUnits.end(),
1434 OtherUnits.begin(), OtherUnits.end())
1435 != CheckUnits.end()) {
1436 // CheckUnits and OtherUnits overlap
1437 OtherUnits.insert(OtherUnits.end(), CheckUnits.begin(),
1438 CheckUnits.end());
1439 if (!hasSuperGroup(OtherUnits, PM)) {
1440 PrintFatalError((PM.ProcResourceDefs[i])->getLoc(),
1441 "proc resource group overlaps with "
1442 + PM.ProcResourceDefs[j]->getName()
1443 + " but no supergroup contains both.");
1444 }
1445 }
1446 }
1447 }
1448}
1449
Andrew Trick1e46d482012-09-15 00:20:02 +00001450// Collect and sort WriteRes, ReadAdvance, and ProcResources.
1451void CodeGenSchedModels::collectProcResources() {
Matthias Braun6b1fd9a2016-06-21 03:24:03 +00001452 ProcResourceDefs = Records.getAllDerivedDefinitions("ProcResourceUnits");
1453 ProcResGroups = Records.getAllDerivedDefinitions("ProcResGroup");
1454
Andrew Trick1e46d482012-09-15 00:20:02 +00001455 // Add any subtarget-specific SchedReadWrites that are directly associated
1456 // with processor resources. Refer to the parent SchedClass's ProcIndices to
1457 // determine which processors they apply to.
1458 for (SchedClassIter SCI = schedClassBegin(), SCE = schedClassEnd();
1459 SCI != SCE; ++SCI) {
1460 if (SCI->ItinClassDef)
1461 collectItinProcResources(SCI->ItinClassDef);
Andrew Trick4fe440d2013-02-01 03:19:54 +00001462 else {
1463 // This class may have a default ReadWrite list which can be overriden by
1464 // InstRW definitions.
1465 if (!SCI->InstRWs.empty()) {
1466 for (RecIter RWI = SCI->InstRWs.begin(), RWE = SCI->InstRWs.end();
1467 RWI != RWE; ++RWI) {
1468 Record *RWModelDef = (*RWI)->getValueAsDef("SchedModel");
1469 IdxVec ProcIndices(1, getProcModel(RWModelDef).Index);
1470 IdxVec Writes, Reads;
1471 findRWs((*RWI)->getValueAsListOfDefs("OperandReadWrites"),
1472 Writes, Reads);
1473 collectRWResources(Writes, Reads, ProcIndices);
1474 }
1475 }
Andrew Trick1e46d482012-09-15 00:20:02 +00001476 collectRWResources(SCI->Writes, SCI->Reads, SCI->ProcIndices);
Andrew Trick4fe440d2013-02-01 03:19:54 +00001477 }
Andrew Trick1e46d482012-09-15 00:20:02 +00001478 }
1479 // Add resources separately defined by each subtarget.
1480 RecVec WRDefs = Records.getAllDerivedDefinitions("WriteRes");
Javed Absar2c9570c2017-10-11 09:33:23 +00001481 for (Record *WR : WRDefs) {
1482 Record *ModelDef = WR->getValueAsDef("SchedModel");
1483 addWriteRes(WR, getProcModel(ModelDef).Index);
Andrew Trick1e46d482012-09-15 00:20:02 +00001484 }
Andrew Trickdca870b2014-03-13 03:49:20 +00001485 RecVec SWRDefs = Records.getAllDerivedDefinitions("SchedWriteRes");
Javed Absar2c9570c2017-10-11 09:33:23 +00001486 for (Record *SWR : SWRDefs) {
1487 Record *ModelDef = SWR->getValueAsDef("SchedModel");
1488 addWriteRes(SWR, getProcModel(ModelDef).Index);
Andrew Trickdca870b2014-03-13 03:49:20 +00001489 }
Andrew Trick1e46d482012-09-15 00:20:02 +00001490 RecVec RADefs = Records.getAllDerivedDefinitions("ReadAdvance");
Javed Absar2c9570c2017-10-11 09:33:23 +00001491 for (Record *RA : RADefs) {
1492 Record *ModelDef = RA->getValueAsDef("SchedModel");
1493 addReadAdvance(RA, getProcModel(ModelDef).Index);
Andrew Trick1e46d482012-09-15 00:20:02 +00001494 }
Andrew Trickdca870b2014-03-13 03:49:20 +00001495 RecVec SRADefs = Records.getAllDerivedDefinitions("SchedReadAdvance");
Javed Absar2c9570c2017-10-11 09:33:23 +00001496 for (Record *SRA : SRADefs) {
1497 if (SRA->getValueInit("SchedModel")->isComplete()) {
1498 Record *ModelDef = SRA->getValueAsDef("SchedModel");
1499 addReadAdvance(SRA, getProcModel(ModelDef).Index);
Andrew Trickdca870b2014-03-13 03:49:20 +00001500 }
1501 }
Andrew Trick40c4f382013-06-15 04:50:06 +00001502 // Add ProcResGroups that are defined within this processor model, which may
1503 // not be directly referenced but may directly specify a buffer size.
1504 RecVec ProcResGroups = Records.getAllDerivedDefinitions("ProcResGroup");
Javed Absar21c75912017-10-09 16:21:25 +00001505 for (Record *PRG : ProcResGroups) {
Javed Absarfc500042017-10-05 13:27:43 +00001506 if (!PRG->getValueInit("SchedModel")->isComplete())
Andrew Trick40c4f382013-06-15 04:50:06 +00001507 continue;
Javed Absarfc500042017-10-05 13:27:43 +00001508 CodeGenProcModel &PM = getProcModel(PRG->getValueAsDef("SchedModel"));
1509 if (!is_contained(PM.ProcResourceDefs, PRG))
1510 PM.ProcResourceDefs.push_back(PRG);
Andrew Trick40c4f382013-06-15 04:50:06 +00001511 }
Andrew Trick1e46d482012-09-15 00:20:02 +00001512 // Finalize each ProcModel by sorting the record arrays.
Craig Topper8a417c12014-12-09 08:05:51 +00001513 for (CodeGenProcModel &PM : ProcModels) {
Andrew Trick1e46d482012-09-15 00:20:02 +00001514 std::sort(PM.WriteResDefs.begin(), PM.WriteResDefs.end(),
1515 LessRecord());
1516 std::sort(PM.ReadAdvanceDefs.begin(), PM.ReadAdvanceDefs.end(),
1517 LessRecord());
1518 std::sort(PM.ProcResourceDefs.begin(), PM.ProcResourceDefs.end(),
1519 LessRecord());
1520 DEBUG(
1521 PM.dump();
1522 dbgs() << "WriteResDefs: ";
1523 for (RecIter RI = PM.WriteResDefs.begin(),
1524 RE = PM.WriteResDefs.end(); RI != RE; ++RI) {
1525 if ((*RI)->isSubClassOf("WriteRes"))
1526 dbgs() << (*RI)->getValueAsDef("WriteType")->getName() << " ";
1527 else
1528 dbgs() << (*RI)->getName() << " ";
1529 }
1530 dbgs() << "\nReadAdvanceDefs: ";
1531 for (RecIter RI = PM.ReadAdvanceDefs.begin(),
1532 RE = PM.ReadAdvanceDefs.end(); RI != RE; ++RI) {
1533 if ((*RI)->isSubClassOf("ReadAdvance"))
1534 dbgs() << (*RI)->getValueAsDef("ReadType")->getName() << " ";
1535 else
1536 dbgs() << (*RI)->getName() << " ";
1537 }
1538 dbgs() << "\nProcResourceDefs: ";
1539 for (RecIter RI = PM.ProcResourceDefs.begin(),
1540 RE = PM.ProcResourceDefs.end(); RI != RE; ++RI) {
1541 dbgs() << (*RI)->getName() << " ";
1542 }
1543 dbgs() << '\n');
Andrew Trickcf398b22013-04-23 23:45:14 +00001544 verifyProcResourceGroups(PM);
Andrew Trick1e46d482012-09-15 00:20:02 +00001545 }
Matthias Braun6b1fd9a2016-06-21 03:24:03 +00001546
1547 ProcResourceDefs.clear();
1548 ProcResGroups.clear();
Andrew Trick1e46d482012-09-15 00:20:02 +00001549}
1550
Matthias Braun17cb5792016-03-01 20:03:21 +00001551void CodeGenSchedModels::checkCompleteness() {
1552 bool Complete = true;
1553 bool HadCompleteModel = false;
1554 for (const CodeGenProcModel &ProcModel : procModels()) {
Matthias Braun17cb5792016-03-01 20:03:21 +00001555 if (!ProcModel.ModelDef->getValueAsBit("CompleteModel"))
1556 continue;
1557 for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) {
1558 if (Inst->hasNoSchedulingInfo)
1559 continue;
Simon Dardis5f95c9a2016-06-24 08:43:27 +00001560 if (ProcModel.isUnsupported(*Inst))
1561 continue;
Matthias Braun17cb5792016-03-01 20:03:21 +00001562 unsigned SCIdx = getSchedClassIdx(*Inst);
1563 if (!SCIdx) {
1564 if (Inst->TheDef->isValueUnset("SchedRW") && !HadCompleteModel) {
1565 PrintError("No schedule information for instruction '"
1566 + Inst->TheDef->getName() + "'");
1567 Complete = false;
1568 }
1569 continue;
1570 }
1571
1572 const CodeGenSchedClass &SC = getSchedClass(SCIdx);
1573 if (!SC.Writes.empty())
1574 continue;
Ulrich Weigand75cda2f2016-10-31 18:59:52 +00001575 if (SC.ItinClassDef != nullptr &&
1576 SC.ItinClassDef->getName() != "NoItinerary")
Matthias Braun42d9ad92016-03-03 00:04:59 +00001577 continue;
Matthias Braun17cb5792016-03-01 20:03:21 +00001578
1579 const RecVec &InstRWs = SC.InstRWs;
David Majnemer562e8292016-08-12 00:18:03 +00001580 auto I = find_if(InstRWs, [&ProcModel](const Record *R) {
1581 return R->getValueAsDef("SchedModel") == ProcModel.ModelDef;
1582 });
Matthias Braun17cb5792016-03-01 20:03:21 +00001583 if (I == InstRWs.end()) {
1584 PrintError("'" + ProcModel.ModelName + "' lacks information for '" +
1585 Inst->TheDef->getName() + "'");
1586 Complete = false;
1587 }
1588 }
1589 HadCompleteModel = true;
1590 }
Matthias Brauna939bd02016-03-01 21:36:12 +00001591 if (!Complete) {
1592 errs() << "\n\nIncomplete schedule models found.\n"
1593 << "- Consider setting 'CompleteModel = 0' while developing new models.\n"
1594 << "- Pseudo instructions can be marked with 'hasNoSchedulingInfo = 1'.\n"
1595 << "- Instructions should usually have Sched<[...]> as a superclass, "
Simon Dardis5f95c9a2016-06-24 08:43:27 +00001596 "you may temporarily use an empty list.\n"
1597 << "- Instructions related to unsupported features can be excluded with "
1598 "list<Predicate> UnsupportedFeatures = [HasA,..,HasY]; in the "
1599 "processor model.\n\n";
Matthias Braun17cb5792016-03-01 20:03:21 +00001600 PrintFatalError("Incomplete schedule model");
Matthias Brauna939bd02016-03-01 21:36:12 +00001601 }
Matthias Braun17cb5792016-03-01 20:03:21 +00001602}
1603
Andrew Trick1e46d482012-09-15 00:20:02 +00001604// Collect itinerary class resources for each processor.
1605void CodeGenSchedModels::collectItinProcResources(Record *ItinClassDef) {
1606 for (unsigned PIdx = 0, PEnd = ProcModels.size(); PIdx != PEnd; ++PIdx) {
1607 const CodeGenProcModel &PM = ProcModels[PIdx];
1608 // For all ItinRW entries.
1609 bool HasMatch = false;
1610 for (RecIter II = PM.ItinRWDefs.begin(), IE = PM.ItinRWDefs.end();
1611 II != IE; ++II) {
1612 RecVec Matched = (*II)->getValueAsListOfDefs("MatchedItinClasses");
1613 if (!std::count(Matched.begin(), Matched.end(), ItinClassDef))
1614 continue;
1615 if (HasMatch)
Joerg Sonnenberger635debe2012-10-25 20:33:17 +00001616 PrintFatalError((*II)->getLoc(), "Duplicate itinerary class "
1617 + ItinClassDef->getName()
1618 + " in ItinResources for " + PM.ModelName);
Andrew Trick1e46d482012-09-15 00:20:02 +00001619 HasMatch = true;
1620 IdxVec Writes, Reads;
1621 findRWs((*II)->getValueAsListOfDefs("OperandReadWrites"), Writes, Reads);
1622 IdxVec ProcIndices(1, PIdx);
1623 collectRWResources(Writes, Reads, ProcIndices);
1624 }
1625 }
1626}
1627
Andrew Trickd0b9c442012-10-10 05:43:13 +00001628void CodeGenSchedModels::collectRWResources(unsigned RWIdx, bool IsRead,
Benjamin Kramere1761952015-10-24 12:46:49 +00001629 ArrayRef<unsigned> ProcIndices) {
Andrew Trickd0b9c442012-10-10 05:43:13 +00001630 const CodeGenSchedRW &SchedRW = getSchedRW(RWIdx, IsRead);
1631 if (SchedRW.TheDef) {
1632 if (!IsRead && SchedRW.TheDef->isSubClassOf("SchedWriteRes")) {
Benjamin Kramere1761952015-10-24 12:46:49 +00001633 for (unsigned Idx : ProcIndices)
1634 addWriteRes(SchedRW.TheDef, Idx);
Andrew Trickd0b9c442012-10-10 05:43:13 +00001635 }
1636 else if (IsRead && SchedRW.TheDef->isSubClassOf("SchedReadAdvance")) {
Benjamin Kramere1761952015-10-24 12:46:49 +00001637 for (unsigned Idx : ProcIndices)
1638 addReadAdvance(SchedRW.TheDef, Idx);
Andrew Trickd0b9c442012-10-10 05:43:13 +00001639 }
1640 }
1641 for (RecIter AI = SchedRW.Aliases.begin(), AE = SchedRW.Aliases.end();
1642 AI != AE; ++AI) {
1643 IdxVec AliasProcIndices;
1644 if ((*AI)->getValueInit("SchedModel")->isComplete()) {
1645 AliasProcIndices.push_back(
1646 getProcModel((*AI)->getValueAsDef("SchedModel")).Index);
1647 }
1648 else
1649 AliasProcIndices = ProcIndices;
1650 const CodeGenSchedRW &AliasRW = getSchedRW((*AI)->getValueAsDef("AliasRW"));
1651 assert(AliasRW.IsRead == IsRead && "cannot alias reads to writes");
1652
1653 IdxVec ExpandedRWs;
1654 expandRWSequence(AliasRW.Index, ExpandedRWs, IsRead);
1655 for (IdxIter SI = ExpandedRWs.begin(), SE = ExpandedRWs.end();
1656 SI != SE; ++SI) {
1657 collectRWResources(*SI, IsRead, AliasProcIndices);
1658 }
1659 }
1660}
Andrew Trick1e46d482012-09-15 00:20:02 +00001661
1662// Collect resources for a set of read/write types and processor indices.
Benjamin Kramere1761952015-10-24 12:46:49 +00001663void CodeGenSchedModels::collectRWResources(ArrayRef<unsigned> Writes,
1664 ArrayRef<unsigned> Reads,
1665 ArrayRef<unsigned> ProcIndices) {
Benjamin Kramere1761952015-10-24 12:46:49 +00001666 for (unsigned Idx : Writes)
1667 collectRWResources(Idx, /*IsRead=*/false, ProcIndices);
Andrew Trickd0b9c442012-10-10 05:43:13 +00001668
Benjamin Kramere1761952015-10-24 12:46:49 +00001669 for (unsigned Idx : Reads)
1670 collectRWResources(Idx, /*IsRead=*/true, ProcIndices);
Andrew Trick1e46d482012-09-15 00:20:02 +00001671}
1672
1673// Find the processor's resource units for this kind of resource.
1674Record *CodeGenSchedModels::findProcResUnits(Record *ProcResKind,
1675 const CodeGenProcModel &PM) const {
1676 if (ProcResKind->isSubClassOf("ProcResourceUnits"))
1677 return ProcResKind;
1678
Craig Topper24064772014-04-15 07:20:03 +00001679 Record *ProcUnitDef = nullptr;
Matthias Braun6b1fd9a2016-06-21 03:24:03 +00001680 assert(!ProcResourceDefs.empty());
1681 assert(!ProcResGroups.empty());
Andrew Trick1e46d482012-09-15 00:20:02 +00001682
Javed Absar67b042c2017-09-13 10:31:10 +00001683 for (Record *ProcResDef : ProcResourceDefs) {
1684 if (ProcResDef->getValueAsDef("Kind") == ProcResKind
1685 && ProcResDef->getValueAsDef("SchedModel") == PM.ModelDef) {
Andrew Trick1e46d482012-09-15 00:20:02 +00001686 if (ProcUnitDef) {
Javed Absar67b042c2017-09-13 10:31:10 +00001687 PrintFatalError(ProcResDef->getLoc(),
Joerg Sonnenberger635debe2012-10-25 20:33:17 +00001688 "Multiple ProcessorResourceUnits associated with "
1689 + ProcResKind->getName());
Andrew Trick1e46d482012-09-15 00:20:02 +00001690 }
Javed Absar67b042c2017-09-13 10:31:10 +00001691 ProcUnitDef = ProcResDef;
Andrew Trick1e46d482012-09-15 00:20:02 +00001692 }
1693 }
Javed Absar67b042c2017-09-13 10:31:10 +00001694 for (Record *ProcResGroup : ProcResGroups) {
1695 if (ProcResGroup == ProcResKind
1696 && ProcResGroup->getValueAsDef("SchedModel") == PM.ModelDef) {
Andrew Trick4e67cba2013-03-14 21:21:50 +00001697 if (ProcUnitDef) {
Javed Absar67b042c2017-09-13 10:31:10 +00001698 PrintFatalError((ProcResGroup)->getLoc(),
Andrew Trick4e67cba2013-03-14 21:21:50 +00001699 "Multiple ProcessorResourceUnits associated with "
1700 + ProcResKind->getName());
1701 }
Javed Absar67b042c2017-09-13 10:31:10 +00001702 ProcUnitDef = ProcResGroup;
Andrew Trick4e67cba2013-03-14 21:21:50 +00001703 }
1704 }
Andrew Trick1e46d482012-09-15 00:20:02 +00001705 if (!ProcUnitDef) {
Joerg Sonnenberger635debe2012-10-25 20:33:17 +00001706 PrintFatalError(ProcResKind->getLoc(),
1707 "No ProcessorResources associated with "
1708 + ProcResKind->getName());
Andrew Trick1e46d482012-09-15 00:20:02 +00001709 }
1710 return ProcUnitDef;
1711}
1712
1713// Iteratively add a resource and its super resources.
1714void CodeGenSchedModels::addProcResource(Record *ProcResKind,
1715 CodeGenProcModel &PM) {
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +00001716 while (true) {
Andrew Trick1e46d482012-09-15 00:20:02 +00001717 Record *ProcResUnits = findProcResUnits(ProcResKind, PM);
1718
1719 // See if this ProcResource is already associated with this processor.
David Majnemer42531262016-08-12 03:55:06 +00001720 if (is_contained(PM.ProcResourceDefs, ProcResUnits))
Andrew Trick1e46d482012-09-15 00:20:02 +00001721 return;
1722
1723 PM.ProcResourceDefs.push_back(ProcResUnits);
Andrew Trick4e67cba2013-03-14 21:21:50 +00001724 if (ProcResUnits->isSubClassOf("ProcResGroup"))
1725 return;
1726
Andrew Trick1e46d482012-09-15 00:20:02 +00001727 if (!ProcResUnits->getValueInit("Super")->isComplete())
1728 return;
1729
1730 ProcResKind = ProcResUnits->getValueAsDef("Super");
1731 }
1732}
1733
1734// Add resources for a SchedWrite to this processor if they don't exist.
1735void CodeGenSchedModels::addWriteRes(Record *ProcWriteResDef, unsigned PIdx) {
Andrew Trick9257b8f2012-09-22 02:24:21 +00001736 assert(PIdx && "don't add resources to an invalid Processor model");
1737
Andrew Trick1e46d482012-09-15 00:20:02 +00001738 RecVec &WRDefs = ProcModels[PIdx].WriteResDefs;
David Majnemer42531262016-08-12 03:55:06 +00001739 if (is_contained(WRDefs, ProcWriteResDef))
Andrew Trick1e46d482012-09-15 00:20:02 +00001740 return;
1741 WRDefs.push_back(ProcWriteResDef);
1742
1743 // Visit ProcResourceKinds referenced by the newly discovered WriteRes.
1744 RecVec ProcResDefs = ProcWriteResDef->getValueAsListOfDefs("ProcResources");
1745 for (RecIter WritePRI = ProcResDefs.begin(), WritePRE = ProcResDefs.end();
1746 WritePRI != WritePRE; ++WritePRI) {
1747 addProcResource(*WritePRI, ProcModels[PIdx]);
1748 }
1749}
1750
1751// Add resources for a ReadAdvance to this processor if they don't exist.
1752void CodeGenSchedModels::addReadAdvance(Record *ProcReadAdvanceDef,
1753 unsigned PIdx) {
1754 RecVec &RADefs = ProcModels[PIdx].ReadAdvanceDefs;
David Majnemer42531262016-08-12 03:55:06 +00001755 if (is_contained(RADefs, ProcReadAdvanceDef))
Andrew Trick1e46d482012-09-15 00:20:02 +00001756 return;
1757 RADefs.push_back(ProcReadAdvanceDef);
1758}
1759
Andrew Trick8fa00f52012-09-17 22:18:43 +00001760unsigned CodeGenProcModel::getProcResourceIdx(Record *PRDef) const {
David Majnemer0d955d02016-08-11 22:21:41 +00001761 RecIter PRPos = find(ProcResourceDefs, PRDef);
Andrew Trick8fa00f52012-09-17 22:18:43 +00001762 if (PRPos == ProcResourceDefs.end())
Joerg Sonnenberger635debe2012-10-25 20:33:17 +00001763 PrintFatalError(PRDef->getLoc(), "ProcResource def is not included in "
1764 "the ProcResources list for " + ModelName);
Andrew Trick8fa00f52012-09-17 22:18:43 +00001765 // Idx=0 is reserved for invalid.
Rafael Espindola72961392012-11-02 20:57:36 +00001766 return 1 + (PRPos - ProcResourceDefs.begin());
Andrew Trick8fa00f52012-09-17 22:18:43 +00001767}
1768
Simon Dardis5f95c9a2016-06-24 08:43:27 +00001769bool CodeGenProcModel::isUnsupported(const CodeGenInstruction &Inst) const {
1770 for (const Record *TheDef : UnsupportedFeaturesDefs) {
1771 for (const Record *PredDef : Inst.TheDef->getValueAsListOfDefs("Predicates")) {
1772 if (TheDef->getName() == PredDef->getName())
1773 return true;
1774 }
1775 }
1776 return false;
1777}
1778
Andrew Trick76686492012-09-15 00:19:57 +00001779#ifndef NDEBUG
1780void CodeGenProcModel::dump() const {
1781 dbgs() << Index << ": " << ModelName << " "
1782 << (ModelDef ? ModelDef->getName() : "inferred") << " "
1783 << (ItinsDef ? ItinsDef->getName() : "no itinerary") << '\n';
1784}
1785
1786void CodeGenSchedRW::dump() const {
1787 dbgs() << Name << (IsVariadic ? " (V) " : " ");
1788 if (IsSequence) {
1789 dbgs() << "(";
1790 dumpIdxVec(Sequence);
1791 dbgs() << ")";
1792 }
1793}
1794
1795void CodeGenSchedClass::dump(const CodeGenSchedModels* SchedModels) const {
Andrew Trickbf8a28d2013-03-16 18:58:55 +00001796 dbgs() << "SCHEDCLASS " << Index << ":" << Name << '\n'
Andrew Trick76686492012-09-15 00:19:57 +00001797 << " Writes: ";
1798 for (unsigned i = 0, N = Writes.size(); i < N; ++i) {
1799 SchedModels->getSchedWrite(Writes[i]).dump();
1800 if (i < N-1) {
1801 dbgs() << '\n';
1802 dbgs().indent(10);
1803 }
1804 }
1805 dbgs() << "\n Reads: ";
1806 for (unsigned i = 0, N = Reads.size(); i < N; ++i) {
1807 SchedModels->getSchedRead(Reads[i]).dump();
1808 if (i < N-1) {
1809 dbgs() << '\n';
1810 dbgs().indent(10);
1811 }
1812 }
1813 dbgs() << "\n ProcIdx: "; dumpIdxVec(ProcIndices); dbgs() << '\n';
Andrew Tricke97978f2013-03-26 21:36:39 +00001814 if (!Transitions.empty()) {
1815 dbgs() << "\n Transitions for Proc ";
Javed Absar67b042c2017-09-13 10:31:10 +00001816 for (const CodeGenSchedTransition &Transition : Transitions) {
1817 dumpIdxVec(Transition.ProcIndices);
Andrew Tricke97978f2013-03-26 21:36:39 +00001818 }
1819 }
Andrew Trick76686492012-09-15 00:19:57 +00001820}
Andrew Trick33401e82012-09-15 00:19:59 +00001821
1822void PredTransitions::dump() const {
1823 dbgs() << "Expanded Variants:\n";
1824 for (std::vector<PredTransition>::const_iterator
1825 TI = TransVec.begin(), TE = TransVec.end(); TI != TE; ++TI) {
1826 dbgs() << "{";
1827 for (SmallVectorImpl<PredCheck>::const_iterator
1828 PCI = TI->PredTerm.begin(), PCE = TI->PredTerm.end();
1829 PCI != PCE; ++PCI) {
1830 if (PCI != TI->PredTerm.begin())
1831 dbgs() << ", ";
1832 dbgs() << SchedModels.getSchedRW(PCI->RWIdx, PCI->IsRead).Name
1833 << ":" << PCI->Predicate->getName();
1834 }
1835 dbgs() << "},\n => {";
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +00001836 for (SmallVectorImpl<SmallVector<unsigned,4>>::const_iterator
Andrew Trick33401e82012-09-15 00:19:59 +00001837 WSI = TI->WriteSequences.begin(), WSE = TI->WriteSequences.end();
1838 WSI != WSE; ++WSI) {
1839 dbgs() << "(";
1840 for (SmallVectorImpl<unsigned>::const_iterator
1841 WI = WSI->begin(), WE = WSI->end(); WI != WE; ++WI) {
1842 if (WI != WSI->begin())
1843 dbgs() << ", ";
1844 dbgs() << SchedModels.getSchedWrite(*WI).Name;
1845 }
1846 dbgs() << "),";
1847 }
1848 dbgs() << "}\n";
1849 }
1850}
Andrew Trick76686492012-09-15 00:19:57 +00001851#endif // NDEBUG