blob: 00768d88daadbef48b875fe121fd4caddab4c6b3 [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 Absarfc500042017-10-05 13:27:43 +0000588 for (const CodeGenProcModel &PM :
589 make_range(ProcModels.begin(), ProcModels.end())) {
590 if (!std::count(ProcIndices.begin(), ProcIndices.end(), PM.Index))
Andrew Trickf9df92c92016-10-18 04:17:44 +0000591 dbgs() << "No machine model for " << Inst->TheDef->getName()
Javed Absarfc500042017-10-05 13:27:43 +0000592 << " on processor " << PM.ModelName << '\n';
Andrew Trickf9df92c92016-10-18 04:17:44 +0000593 }
Andrew Trick87255e32012-07-07 04:00:00 +0000594 }
595 }
Andrew Trick76686492012-09-15 00:19:57 +0000596}
597
Andrew Trick76686492012-09-15 00:19:57 +0000598/// Find an SchedClass that has been inferred from a per-operand list of
599/// SchedWrites and SchedReads.
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000600unsigned CodeGenSchedModels::findSchedClassIdx(Record *ItinClassDef,
Benjamin Kramere1761952015-10-24 12:46:49 +0000601 ArrayRef<unsigned> Writes,
602 ArrayRef<unsigned> Reads) const {
Andrew Trick76686492012-09-15 00:19:57 +0000603 for (SchedClassIter I = schedClassBegin(), E = schedClassEnd(); I != E; ++I) {
Benjamin Kramere1761952015-10-24 12:46:49 +0000604 if (I->ItinClassDef == ItinClassDef && makeArrayRef(I->Writes) == Writes &&
605 makeArrayRef(I->Reads) == Reads) {
Andrew Trick76686492012-09-15 00:19:57 +0000606 return I - schedClassBegin();
607 }
Andrew Trick87255e32012-07-07 04:00:00 +0000608 }
Andrew Trick76686492012-09-15 00:19:57 +0000609 return 0;
610}
Andrew Trick87255e32012-07-07 04:00:00 +0000611
Andrew Trick76686492012-09-15 00:19:57 +0000612// Get the SchedClass index for an instruction.
613unsigned CodeGenSchedModels::getSchedClassIdx(
614 const CodeGenInstruction &Inst) const {
Andrew Trick87255e32012-07-07 04:00:00 +0000615
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000616 return InstrClassMap.lookup(Inst.TheDef);
Andrew Trick76686492012-09-15 00:19:57 +0000617}
618
Benjamin Kramere1761952015-10-24 12:46:49 +0000619std::string
620CodeGenSchedModels::createSchedClassName(Record *ItinClassDef,
621 ArrayRef<unsigned> OperWrites,
622 ArrayRef<unsigned> OperReads) {
Andrew Trick76686492012-09-15 00:19:57 +0000623
624 std::string Name;
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000625 if (ItinClassDef && ItinClassDef->getName() != "NoItinerary")
626 Name = ItinClassDef->getName();
Benjamin Kramere1761952015-10-24 12:46:49 +0000627 for (unsigned Idx : OperWrites) {
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000628 if (!Name.empty())
Andrew Trick76686492012-09-15 00:19:57 +0000629 Name += '_';
Benjamin Kramere1761952015-10-24 12:46:49 +0000630 Name += SchedWrites[Idx].Name;
Andrew Trick76686492012-09-15 00:19:57 +0000631 }
Benjamin Kramere1761952015-10-24 12:46:49 +0000632 for (unsigned Idx : OperReads) {
Andrew Trick76686492012-09-15 00:19:57 +0000633 Name += '_';
Benjamin Kramere1761952015-10-24 12:46:49 +0000634 Name += SchedReads[Idx].Name;
Andrew Trick76686492012-09-15 00:19:57 +0000635 }
636 return Name;
637}
638
639std::string CodeGenSchedModels::createSchedClassName(const RecVec &InstDefs) {
640
641 std::string Name;
642 for (RecIter I = InstDefs.begin(), E = InstDefs.end(); I != E; ++I) {
643 if (I != InstDefs.begin())
644 Name += '_';
645 Name += (*I)->getName();
646 }
647 return Name;
648}
649
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000650/// Add an inferred sched class from an itinerary class and per-operand list of
651/// SchedWrites and SchedReads. ProcIndices contains the set of IDs of
652/// processors that may utilize this class.
653unsigned CodeGenSchedModels::addSchedClass(Record *ItinClassDef,
Benjamin Kramere1761952015-10-24 12:46:49 +0000654 ArrayRef<unsigned> OperWrites,
655 ArrayRef<unsigned> OperReads,
656 ArrayRef<unsigned> ProcIndices) {
Andrew Trick76686492012-09-15 00:19:57 +0000657 assert(!ProcIndices.empty() && "expect at least one ProcIdx");
658
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000659 unsigned Idx = findSchedClassIdx(ItinClassDef, OperWrites, OperReads);
660 if (Idx || SchedClasses[0].isKeyEqual(ItinClassDef, OperWrites, OperReads)) {
Andrew Trick76686492012-09-15 00:19:57 +0000661 IdxVec PI;
662 std::set_union(SchedClasses[Idx].ProcIndices.begin(),
663 SchedClasses[Idx].ProcIndices.end(),
664 ProcIndices.begin(), ProcIndices.end(),
665 std::back_inserter(PI));
666 SchedClasses[Idx].ProcIndices.swap(PI);
667 return Idx;
668 }
669 Idx = SchedClasses.size();
670 SchedClasses.resize(Idx+1);
671 CodeGenSchedClass &SC = SchedClasses.back();
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000672 SC.Index = Idx;
673 SC.Name = createSchedClassName(ItinClassDef, OperWrites, OperReads);
674 SC.ItinClassDef = ItinClassDef;
Andrew Trick76686492012-09-15 00:19:57 +0000675 SC.Writes = OperWrites;
676 SC.Reads = OperReads;
677 SC.ProcIndices = ProcIndices;
678
679 return Idx;
680}
681
682// Create classes for each set of opcodes that are in the same InstReadWrite
683// definition across all processors.
684void CodeGenSchedModels::createInstRWClass(Record *InstRWDef) {
685 // ClassInstrs will hold an entry for each subset of Instrs in InstRWDef that
686 // intersects with an existing class via a previous InstRWDef. Instrs that do
687 // not intersect with an existing class refer back to their former class as
688 // determined from ItinDef or SchedRW.
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +0000689 SmallVector<std::pair<unsigned, SmallVector<Record *, 8>>, 4> ClassInstrs;
Andrew Trick76686492012-09-15 00:19:57 +0000690 // Sort Instrs into sets.
Andrew Trick9e1deb62012-10-03 23:06:32 +0000691 const RecVec *InstDefs = Sets.expand(InstRWDef);
692 if (InstDefs->empty())
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000693 PrintFatalError(InstRWDef->getLoc(), "No matching instruction opcodes");
Andrew Trick9e1deb62012-10-03 23:06:32 +0000694
Javed Absarfc500042017-10-05 13:27:43 +0000695 for (Record *InstDef : make_range(InstDefs->begin(), InstDefs->end())) {
696 InstClassMapTy::const_iterator Pos = InstrClassMap.find(InstDef);
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000697 if (Pos == InstrClassMap.end())
Javed Absarfc500042017-10-05 13:27:43 +0000698 PrintFatalError(InstDef->getLoc(), "No sched class for instruction.");
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000699 unsigned SCIdx = Pos->second;
Andrew Trick76686492012-09-15 00:19:57 +0000700 unsigned CIdx = 0, CEnd = ClassInstrs.size();
701 for (; CIdx != CEnd; ++CIdx) {
702 if (ClassInstrs[CIdx].first == SCIdx)
703 break;
704 }
705 if (CIdx == CEnd) {
706 ClassInstrs.resize(CEnd + 1);
707 ClassInstrs[CIdx].first = SCIdx;
708 }
Javed Absarfc500042017-10-05 13:27:43 +0000709 ClassInstrs[CIdx].second.push_back(InstDef);
Andrew Trick76686492012-09-15 00:19:57 +0000710 }
711 // For each set of Instrs, create a new class if necessary, and map or remap
712 // the Instrs to it.
713 unsigned CIdx = 0, CEnd = ClassInstrs.size();
714 for (; CIdx != CEnd; ++CIdx) {
715 unsigned OldSCIdx = ClassInstrs[CIdx].first;
716 ArrayRef<Record*> InstDefs = ClassInstrs[CIdx].second;
717 // If the all instrs in the current class are accounted for, then leave
718 // them mapped to their old class.
Andrew Trick78a08512013-06-05 06:55:20 +0000719 if (OldSCIdx) {
720 const RecVec &RWDefs = SchedClasses[OldSCIdx].InstRWs;
721 if (!RWDefs.empty()) {
722 const RecVec *OrigInstDefs = Sets.expand(RWDefs[0]);
723 unsigned OrigNumInstrs = 0;
Javed Absar67b042c2017-09-13 10:31:10 +0000724 for (Record *OIDef : make_range(OrigInstDefs->begin(), OrigInstDefs->end())) {
725 if (InstrClassMap[OIDef] == OldSCIdx)
Andrew Trick78a08512013-06-05 06:55:20 +0000726 ++OrigNumInstrs;
727 }
728 if (OrigNumInstrs == InstDefs.size()) {
729 assert(SchedClasses[OldSCIdx].ProcIndices[0] == 0 &&
730 "expected a generic SchedClass");
731 DEBUG(dbgs() << "InstRW: Reuse SC " << OldSCIdx << ":"
732 << SchedClasses[OldSCIdx].Name << " on "
733 << InstRWDef->getValueAsDef("SchedModel")->getName() << "\n");
734 SchedClasses[OldSCIdx].InstRWs.push_back(InstRWDef);
735 continue;
736 }
737 }
Andrew Trick76686492012-09-15 00:19:57 +0000738 }
739 unsigned SCIdx = SchedClasses.size();
740 SchedClasses.resize(SCIdx+1);
741 CodeGenSchedClass &SC = SchedClasses.back();
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000742 SC.Index = SCIdx;
Andrew Trick76686492012-09-15 00:19:57 +0000743 SC.Name = createSchedClassName(InstDefs);
Andrew Trick78a08512013-06-05 06:55:20 +0000744 DEBUG(dbgs() << "InstRW: New SC " << SCIdx << ":" << SC.Name << " on "
745 << InstRWDef->getValueAsDef("SchedModel")->getName() << "\n");
746
Andrew Trick76686492012-09-15 00:19:57 +0000747 // Preserve ItinDef and Writes/Reads for processors without an InstRW entry.
748 SC.ItinClassDef = SchedClasses[OldSCIdx].ItinClassDef;
749 SC.Writes = SchedClasses[OldSCIdx].Writes;
750 SC.Reads = SchedClasses[OldSCIdx].Reads;
751 SC.ProcIndices.push_back(0);
752 // Map each Instr to this new class.
753 // Note that InstDefs may be a smaller list than InstRWDef's "Instrs".
Andrew Trick9e1deb62012-10-03 23:06:32 +0000754 Record *RWModelDef = InstRWDef->getValueAsDef("SchedModel");
755 SmallSet<unsigned, 4> RemappedClassIDs;
Andrew Trick76686492012-09-15 00:19:57 +0000756 for (ArrayRef<Record*>::const_iterator
757 II = InstDefs.begin(), IE = InstDefs.end(); II != IE; ++II) {
758 unsigned OldSCIdx = InstrClassMap[*II];
David Blaikie70573dc2014-11-19 07:49:26 +0000759 if (OldSCIdx && RemappedClassIDs.insert(OldSCIdx).second) {
Andrew Trick9e1deb62012-10-03 23:06:32 +0000760 for (RecIter RI = SchedClasses[OldSCIdx].InstRWs.begin(),
761 RE = SchedClasses[OldSCIdx].InstRWs.end(); RI != RE; ++RI) {
762 if ((*RI)->getValueAsDef("SchedModel") == RWModelDef) {
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000763 PrintFatalError(InstRWDef->getLoc(), "Overlapping InstRW def " +
Andrew Trick9e1deb62012-10-03 23:06:32 +0000764 (*II)->getName() + " also matches " +
765 (*RI)->getValue("Instrs")->getValue()->getAsString());
766 }
767 assert(*RI != InstRWDef && "SchedClass has duplicate InstRW def");
768 SC.InstRWs.push_back(*RI);
769 }
Andrew Trick76686492012-09-15 00:19:57 +0000770 }
771 InstrClassMap[*II] = SCIdx;
772 }
773 SC.InstRWs.push_back(InstRWDef);
774 }
Andrew Trick87255e32012-07-07 04:00:00 +0000775}
776
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000777// True if collectProcItins found anything.
778bool CodeGenSchedModels::hasItineraries() const {
Javed Absar67b042c2017-09-13 10:31:10 +0000779 for (const CodeGenProcModel &PM : make_range(procModelBegin(),procModelEnd())) {
780 if (PM.hasItineraries())
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000781 return true;
782 }
783 return false;
784}
785
Andrew Trick87255e32012-07-07 04:00:00 +0000786// Gather the processor itineraries.
Andrew Trick76686492012-09-15 00:19:57 +0000787void CodeGenSchedModels::collectProcItins() {
Joel Jones80372332017-06-28 00:06:40 +0000788 DEBUG(dbgs() << "\n+++ PROBLEM ITINERARIES (collectProcItins) +++\n");
Craig Topper8a417c12014-12-09 08:05:51 +0000789 for (CodeGenProcModel &ProcModel : ProcModels) {
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000790 if (!ProcModel.hasItineraries())
Andrew Trick87255e32012-07-07 04:00:00 +0000791 continue;
Andrew Trick76686492012-09-15 00:19:57 +0000792
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000793 RecVec ItinRecords = ProcModel.ItinsDef->getValueAsListOfDefs("IID");
794 assert(!ItinRecords.empty() && "ProcModel.hasItineraries is incorrect");
795
796 // Populate ItinDefList with Itinerary records.
797 ProcModel.ItinDefList.resize(NumInstrSchedClasses);
Andrew Trick76686492012-09-15 00:19:57 +0000798
799 // Insert each itinerary data record in the correct position within
800 // the processor model's ItinDefList.
Javed Absarfc500042017-10-05 13:27:43 +0000801 for (Record *ItinData : ItinRecords) {
Andrew Trick76686492012-09-15 00:19:57 +0000802 Record *ItinDef = ItinData->getValueAsDef("TheClass");
Andrew Tricke7bac5f2013-03-18 20:42:25 +0000803 bool FoundClass = false;
804 for (SchedClassIter SCI = schedClassBegin(), SCE = schedClassEnd();
805 SCI != SCE; ++SCI) {
806 // Multiple SchedClasses may share an itinerary. Update all of them.
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000807 if (SCI->ItinClassDef == ItinDef) {
808 ProcModel.ItinDefList[SCI->Index] = ItinData;
Andrew Tricke7bac5f2013-03-18 20:42:25 +0000809 FoundClass = true;
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000810 }
Andrew Trick76686492012-09-15 00:19:57 +0000811 }
Andrew Tricke7bac5f2013-03-18 20:42:25 +0000812 if (!FoundClass) {
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000813 DEBUG(dbgs() << ProcModel.ItinsDef->getName()
814 << " missing class for itinerary " << ItinDef->getName() << '\n');
815 }
Andrew Trick87255e32012-07-07 04:00:00 +0000816 }
Andrew Trick76686492012-09-15 00:19:57 +0000817 // Check for missing itinerary entries.
818 assert(!ProcModel.ItinDefList[0] && "NoItinerary class can't have rec");
819 DEBUG(
820 for (unsigned i = 1, N = ProcModel.ItinDefList.size(); i < N; ++i) {
821 if (!ProcModel.ItinDefList[i])
822 dbgs() << ProcModel.ItinsDef->getName()
823 << " missing itinerary for class "
824 << SchedClasses[i].Name << '\n';
825 });
Andrew Trick87255e32012-07-07 04:00:00 +0000826 }
Andrew Trick87255e32012-07-07 04:00:00 +0000827}
Andrew Trick76686492012-09-15 00:19:57 +0000828
829// Gather the read/write types for each itinerary class.
830void CodeGenSchedModels::collectProcItinRW() {
831 RecVec ItinRWDefs = Records.getAllDerivedDefinitions("ItinRW");
832 std::sort(ItinRWDefs.begin(), ItinRWDefs.end(), LessRecord());
833 for (RecIter II = ItinRWDefs.begin(), IE = ItinRWDefs.end(); II != IE; ++II) {
834 if (!(*II)->getValueInit("SchedModel")->isComplete())
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000835 PrintFatalError((*II)->getLoc(), "SchedModel is undefined");
Andrew Trick76686492012-09-15 00:19:57 +0000836 Record *ModelDef = (*II)->getValueAsDef("SchedModel");
837 ProcModelMapTy::const_iterator I = ProcModelMap.find(ModelDef);
838 if (I == ProcModelMap.end()) {
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000839 PrintFatalError((*II)->getLoc(), "Undefined SchedMachineModel "
Andrew Trick76686492012-09-15 00:19:57 +0000840 + ModelDef->getName());
841 }
842 ProcModels[I->second].ItinRWDefs.push_back(*II);
843 }
844}
845
Simon Dardis5f95c9a2016-06-24 08:43:27 +0000846// Gather the unsupported features for processor models.
847void CodeGenSchedModels::collectProcUnsupportedFeatures() {
848 for (CodeGenProcModel &ProcModel : ProcModels) {
849 for (Record *Pred : ProcModel.ModelDef->getValueAsListOfDefs("UnsupportedFeatures")) {
850 ProcModel.UnsupportedFeaturesDefs.push_back(Pred);
851 }
852 }
853}
854
Andrew Trick33401e82012-09-15 00:19:59 +0000855/// Infer new classes from existing classes. In the process, this may create new
856/// SchedWrites from sequences of existing SchedWrites.
857void CodeGenSchedModels::inferSchedClasses() {
Joel Jones80372332017-06-28 00:06:40 +0000858 DEBUG(dbgs() << "\n+++ INFERRING SCHED CLASSES (inferSchedClasses) +++\n");
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000859 DEBUG(dbgs() << NumInstrSchedClasses << " instr sched classes.\n");
860
Andrew Trick33401e82012-09-15 00:19:59 +0000861 // Visit all existing classes and newly created classes.
862 for (unsigned Idx = 0; Idx != SchedClasses.size(); ++Idx) {
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000863 assert(SchedClasses[Idx].Index == Idx && "bad SCIdx");
864
Andrew Trick33401e82012-09-15 00:19:59 +0000865 if (SchedClasses[Idx].ItinClassDef)
866 inferFromItinClass(SchedClasses[Idx].ItinClassDef, Idx);
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000867 if (!SchedClasses[Idx].InstRWs.empty())
Andrew Trick33401e82012-09-15 00:19:59 +0000868 inferFromInstRWs(Idx);
Andrew Trickbf8a28d2013-03-16 18:58:55 +0000869 if (!SchedClasses[Idx].Writes.empty()) {
Andrew Trick33401e82012-09-15 00:19:59 +0000870 inferFromRW(SchedClasses[Idx].Writes, SchedClasses[Idx].Reads,
871 Idx, SchedClasses[Idx].ProcIndices);
872 }
873 assert(SchedClasses.size() < (NumInstrSchedClasses*6) &&
874 "too many SchedVariants");
875 }
876}
877
878/// Infer classes from per-processor itinerary resources.
879void CodeGenSchedModels::inferFromItinClass(Record *ItinClassDef,
880 unsigned FromClassIdx) {
881 for (unsigned PIdx = 0, PEnd = ProcModels.size(); PIdx != PEnd; ++PIdx) {
882 const CodeGenProcModel &PM = ProcModels[PIdx];
883 // For all ItinRW entries.
884 bool HasMatch = false;
885 for (RecIter II = PM.ItinRWDefs.begin(), IE = PM.ItinRWDefs.end();
886 II != IE; ++II) {
887 RecVec Matched = (*II)->getValueAsListOfDefs("MatchedItinClasses");
888 if (!std::count(Matched.begin(), Matched.end(), ItinClassDef))
889 continue;
890 if (HasMatch)
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000891 PrintFatalError((*II)->getLoc(), "Duplicate itinerary class "
Andrew Trick33401e82012-09-15 00:19:59 +0000892 + ItinClassDef->getName()
893 + " in ItinResources for " + PM.ModelName);
894 HasMatch = true;
895 IdxVec Writes, Reads;
896 findRWs((*II)->getValueAsListOfDefs("OperandReadWrites"), Writes, Reads);
897 IdxVec ProcIndices(1, PIdx);
898 inferFromRW(Writes, Reads, FromClassIdx, ProcIndices);
899 }
900 }
901}
902
903/// Infer classes from per-processor InstReadWrite definitions.
904void CodeGenSchedModels::inferFromInstRWs(unsigned SCIdx) {
Benjamin Kramer58bd79c2013-06-09 15:20:23 +0000905 for (unsigned I = 0, E = SchedClasses[SCIdx].InstRWs.size(); I != E; ++I) {
Benjamin Kramerb22643a2013-06-10 20:19:35 +0000906 assert(SchedClasses[SCIdx].InstRWs.size() == E && "InstrRWs was mutated!");
Benjamin Kramer58bd79c2013-06-09 15:20:23 +0000907 Record *Rec = SchedClasses[SCIdx].InstRWs[I];
908 const RecVec *InstDefs = Sets.expand(Rec);
Andrew Trick9e1deb62012-10-03 23:06:32 +0000909 RecIter II = InstDefs->begin(), IE = InstDefs->end();
Andrew Trick33401e82012-09-15 00:19:59 +0000910 for (; II != IE; ++II) {
911 if (InstrClassMap[*II] == SCIdx)
912 break;
913 }
914 // If this class no longer has any instructions mapped to it, it has become
915 // irrelevant.
916 if (II == IE)
917 continue;
918 IdxVec Writes, Reads;
Benjamin Kramer58bd79c2013-06-09 15:20:23 +0000919 findRWs(Rec->getValueAsListOfDefs("OperandReadWrites"), Writes, Reads);
920 unsigned PIdx = getProcModel(Rec->getValueAsDef("SchedModel")).Index;
Andrew Trick33401e82012-09-15 00:19:59 +0000921 IdxVec ProcIndices(1, PIdx);
Benjamin Kramer58bd79c2013-06-09 15:20:23 +0000922 inferFromRW(Writes, Reads, SCIdx, ProcIndices); // May mutate SchedClasses.
Andrew Trick33401e82012-09-15 00:19:59 +0000923 }
924}
925
926namespace {
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +0000927
Andrew Trick9257b8f2012-09-22 02:24:21 +0000928// Helper for substituteVariantOperand.
929struct TransVariant {
Andrew Trickda984b12012-10-03 23:06:28 +0000930 Record *VarOrSeqDef; // Variant or sequence.
931 unsigned RWIdx; // Index of this variant or sequence's matched type.
Andrew Trick9257b8f2012-09-22 02:24:21 +0000932 unsigned ProcIdx; // Processor model index or zero for any.
933 unsigned TransVecIdx; // Index into PredTransitions::TransVec.
934
935 TransVariant(Record *def, unsigned rwi, unsigned pi, unsigned ti):
Andrew Trickda984b12012-10-03 23:06:28 +0000936 VarOrSeqDef(def), RWIdx(rwi), ProcIdx(pi), TransVecIdx(ti) {}
Andrew Trick9257b8f2012-09-22 02:24:21 +0000937};
938
Andrew Trick33401e82012-09-15 00:19:59 +0000939// Associate a predicate with the SchedReadWrite that it guards.
940// RWIdx is the index of the read/write variant.
941struct PredCheck {
942 bool IsRead;
943 unsigned RWIdx;
944 Record *Predicate;
945
946 PredCheck(bool r, unsigned w, Record *p): IsRead(r), RWIdx(w), Predicate(p) {}
947};
948
949// A Predicate transition is a list of RW sequences guarded by a PredTerm.
950struct PredTransition {
951 // A predicate term is a conjunction of PredChecks.
952 SmallVector<PredCheck, 4> PredTerm;
953 SmallVector<SmallVector<unsigned,4>, 16> WriteSequences;
954 SmallVector<SmallVector<unsigned,4>, 16> ReadSequences;
Andrew Trick9257b8f2012-09-22 02:24:21 +0000955 SmallVector<unsigned, 4> ProcIndices;
Andrew Trick33401e82012-09-15 00:19:59 +0000956};
957
958// Encapsulate a set of partially constructed transitions.
959// The results are built by repeated calls to substituteVariants.
960class PredTransitions {
961 CodeGenSchedModels &SchedModels;
962
963public:
964 std::vector<PredTransition> TransVec;
965
966 PredTransitions(CodeGenSchedModels &sm): SchedModels(sm) {}
967
968 void substituteVariantOperand(const SmallVectorImpl<unsigned> &RWSeq,
969 bool IsRead, unsigned StartIdx);
970
971 void substituteVariants(const PredTransition &Trans);
972
973#ifndef NDEBUG
974 void dump() const;
975#endif
976
977private:
978 bool mutuallyExclusive(Record *PredDef, ArrayRef<PredCheck> Term);
Andrew Trickda984b12012-10-03 23:06:28 +0000979 void getIntersectingVariants(
980 const CodeGenSchedRW &SchedRW, unsigned TransIdx,
981 std::vector<TransVariant> &IntersectingVariants);
Andrew Trick9257b8f2012-09-22 02:24:21 +0000982 void pushVariant(const TransVariant &VInfo, bool IsRead);
Andrew Trick33401e82012-09-15 00:19:59 +0000983};
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +0000984
985} // end anonymous namespace
Andrew Trick33401e82012-09-15 00:19:59 +0000986
987// Return true if this predicate is mutually exclusive with a PredTerm. This
988// degenerates into checking if the predicate is mutually exclusive with any
989// predicate in the Term's conjunction.
990//
991// All predicates associated with a given SchedRW are considered mutually
992// exclusive. This should work even if the conditions expressed by the
993// predicates are not exclusive because the predicates for a given SchedWrite
994// are always checked in the order they are defined in the .td file. Later
995// conditions implicitly negate any prior condition.
996bool PredTransitions::mutuallyExclusive(Record *PredDef,
997 ArrayRef<PredCheck> Term) {
Javed Absarfc500042017-10-05 13:27:43 +0000998 for (const PredCheck &PC: make_range(Term.begin(), Term.end())) {
999 if (PC.Predicate == PredDef)
Andrew Trick33401e82012-09-15 00:19:59 +00001000 return false;
1001
Javed Absarfc500042017-10-05 13:27:43 +00001002 const CodeGenSchedRW &SchedRW = SchedModels.getSchedRW(PC.RWIdx, PC.IsRead);
Andrew Trick33401e82012-09-15 00:19:59 +00001003 assert(SchedRW.HasVariants && "PredCheck must refer to a SchedVariant");
1004 RecVec Variants = SchedRW.TheDef->getValueAsListOfDefs("Variants");
1005 for (RecIter VI = Variants.begin(), VE = Variants.end(); VI != VE; ++VI) {
1006 if ((*VI)->getValueAsDef("Predicate") == PredDef)
1007 return true;
1008 }
1009 }
1010 return false;
1011}
1012
Andrew Trickda984b12012-10-03 23:06:28 +00001013static bool hasAliasedVariants(const CodeGenSchedRW &RW,
1014 CodeGenSchedModels &SchedModels) {
1015 if (RW.HasVariants)
1016 return true;
1017
Javed Absarfc500042017-10-05 13:27:43 +00001018 for (Record *Alias : make_range(RW.Aliases.begin(), RW.Aliases.end())) {
Andrew Trickda984b12012-10-03 23:06:28 +00001019 const CodeGenSchedRW &AliasRW =
Javed Absarfc500042017-10-05 13:27:43 +00001020 SchedModels.getSchedRW(Alias->getValueAsDef("AliasRW"));
Andrew Trickda984b12012-10-03 23:06:28 +00001021 if (AliasRW.HasVariants)
1022 return true;
1023 if (AliasRW.IsSequence) {
1024 IdxVec ExpandedRWs;
1025 SchedModels.expandRWSequence(AliasRW.Index, ExpandedRWs, AliasRW.IsRead);
1026 for (IdxIter SI = ExpandedRWs.begin(), SE = ExpandedRWs.end();
1027 SI != SE; ++SI) {
1028 if (hasAliasedVariants(SchedModels.getSchedRW(*SI, AliasRW.IsRead),
1029 SchedModels)) {
1030 return true;
1031 }
1032 }
1033 }
1034 }
1035 return false;
1036}
1037
1038static bool hasVariant(ArrayRef<PredTransition> Transitions,
1039 CodeGenSchedModels &SchedModels) {
1040 for (ArrayRef<PredTransition>::iterator
1041 PTI = Transitions.begin(), PTE = Transitions.end();
1042 PTI != PTE; ++PTI) {
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +00001043 for (SmallVectorImpl<SmallVector<unsigned,4>>::const_iterator
Andrew Trickda984b12012-10-03 23:06:28 +00001044 WSI = PTI->WriteSequences.begin(), WSE = PTI->WriteSequences.end();
1045 WSI != WSE; ++WSI) {
1046 for (SmallVectorImpl<unsigned>::const_iterator
1047 WI = WSI->begin(), WE = WSI->end(); WI != WE; ++WI) {
1048 if (hasAliasedVariants(SchedModels.getSchedWrite(*WI), SchedModels))
1049 return true;
1050 }
1051 }
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +00001052 for (SmallVectorImpl<SmallVector<unsigned,4>>::const_iterator
Andrew Trickda984b12012-10-03 23:06:28 +00001053 RSI = PTI->ReadSequences.begin(), RSE = PTI->ReadSequences.end();
1054 RSI != RSE; ++RSI) {
1055 for (SmallVectorImpl<unsigned>::const_iterator
1056 RI = RSI->begin(), RE = RSI->end(); RI != RE; ++RI) {
1057 if (hasAliasedVariants(SchedModels.getSchedRead(*RI), SchedModels))
1058 return true;
1059 }
1060 }
1061 }
1062 return false;
1063}
1064
1065// Populate IntersectingVariants with any variants or aliased sequences of the
1066// given SchedRW whose processor indices and predicates are not mutually
Andrew Trickd97ff1f2013-03-29 19:08:31 +00001067// exclusive with the given transition.
Andrew Trickda984b12012-10-03 23:06:28 +00001068void PredTransitions::getIntersectingVariants(
1069 const CodeGenSchedRW &SchedRW, unsigned TransIdx,
1070 std::vector<TransVariant> &IntersectingVariants) {
1071
Andrew Trickd97ff1f2013-03-29 19:08:31 +00001072 bool GenericRW = false;
1073
Andrew Trickda984b12012-10-03 23:06:28 +00001074 std::vector<TransVariant> Variants;
1075 if (SchedRW.HasVariants) {
1076 unsigned VarProcIdx = 0;
1077 if (SchedRW.TheDef->getValueInit("SchedModel")->isComplete()) {
1078 Record *ModelDef = SchedRW.TheDef->getValueAsDef("SchedModel");
1079 VarProcIdx = SchedModels.getProcModel(ModelDef).Index;
1080 }
1081 // Push each variant. Assign TransVecIdx later.
1082 const RecVec VarDefs = SchedRW.TheDef->getValueAsListOfDefs("Variants");
1083 for (RecIter RI = VarDefs.begin(), RE = VarDefs.end(); RI != RE; ++RI)
1084 Variants.push_back(TransVariant(*RI, SchedRW.Index, VarProcIdx, 0));
Andrew Trickd97ff1f2013-03-29 19:08:31 +00001085 if (VarProcIdx == 0)
1086 GenericRW = true;
Andrew Trickda984b12012-10-03 23:06:28 +00001087 }
1088 for (RecIter AI = SchedRW.Aliases.begin(), AE = SchedRW.Aliases.end();
1089 AI != AE; ++AI) {
1090 // If either the SchedAlias itself or the SchedReadWrite that it aliases
1091 // to is defined within a processor model, constrain all variants to
1092 // that processor.
1093 unsigned AliasProcIdx = 0;
1094 if ((*AI)->getValueInit("SchedModel")->isComplete()) {
1095 Record *ModelDef = (*AI)->getValueAsDef("SchedModel");
1096 AliasProcIdx = SchedModels.getProcModel(ModelDef).Index;
1097 }
1098 const CodeGenSchedRW &AliasRW =
1099 SchedModels.getSchedRW((*AI)->getValueAsDef("AliasRW"));
1100
1101 if (AliasRW.HasVariants) {
1102 const RecVec VarDefs = AliasRW.TheDef->getValueAsListOfDefs("Variants");
1103 for (RecIter RI = VarDefs.begin(), RE = VarDefs.end(); RI != RE; ++RI)
1104 Variants.push_back(TransVariant(*RI, AliasRW.Index, AliasProcIdx, 0));
1105 }
1106 if (AliasRW.IsSequence) {
1107 Variants.push_back(
1108 TransVariant(AliasRW.TheDef, SchedRW.Index, AliasProcIdx, 0));
1109 }
Andrew Trickd97ff1f2013-03-29 19:08:31 +00001110 if (AliasProcIdx == 0)
1111 GenericRW = true;
Andrew Trickda984b12012-10-03 23:06:28 +00001112 }
1113 for (unsigned VIdx = 0, VEnd = Variants.size(); VIdx != VEnd; ++VIdx) {
1114 TransVariant &Variant = Variants[VIdx];
1115 // Don't expand variants if the processor models don't intersect.
1116 // A zero processor index means any processor.
Craig Topperb94011f2013-07-14 04:42:23 +00001117 SmallVectorImpl<unsigned> &ProcIndices = TransVec[TransIdx].ProcIndices;
Andrew Trickda984b12012-10-03 23:06:28 +00001118 if (ProcIndices[0] && Variants[VIdx].ProcIdx) {
1119 unsigned Cnt = std::count(ProcIndices.begin(), ProcIndices.end(),
1120 Variant.ProcIdx);
1121 if (!Cnt)
1122 continue;
1123 if (Cnt > 1) {
1124 const CodeGenProcModel &PM =
1125 *(SchedModels.procModelBegin() + Variant.ProcIdx);
Joerg Sonnenberger635debe2012-10-25 20:33:17 +00001126 PrintFatalError(Variant.VarOrSeqDef->getLoc(),
1127 "Multiple variants defined for processor " +
1128 PM.ModelName +
1129 " Ensure only one SchedAlias exists per RW.");
Andrew Trickda984b12012-10-03 23:06:28 +00001130 }
1131 }
1132 if (Variant.VarOrSeqDef->isSubClassOf("SchedVar")) {
1133 Record *PredDef = Variant.VarOrSeqDef->getValueAsDef("Predicate");
1134 if (mutuallyExclusive(PredDef, TransVec[TransIdx].PredTerm))
1135 continue;
1136 }
1137 if (IntersectingVariants.empty()) {
1138 // The first variant builds on the existing transition.
1139 Variant.TransVecIdx = TransIdx;
1140 IntersectingVariants.push_back(Variant);
1141 }
1142 else {
1143 // Push another copy of the current transition for more variants.
1144 Variant.TransVecIdx = TransVec.size();
1145 IntersectingVariants.push_back(Variant);
Dan Gohmanf6169d02013-03-29 00:13:08 +00001146 TransVec.push_back(TransVec[TransIdx]);
Andrew Trickda984b12012-10-03 23:06:28 +00001147 }
1148 }
Andrew Trickd97ff1f2013-03-29 19:08:31 +00001149 if (GenericRW && IntersectingVariants.empty()) {
1150 PrintFatalError(SchedRW.TheDef->getLoc(), "No variant of this type has "
1151 "a matching predicate on any processor");
1152 }
Andrew Trickda984b12012-10-03 23:06:28 +00001153}
1154
Andrew Trick9257b8f2012-09-22 02:24:21 +00001155// Push the Reads/Writes selected by this variant onto the PredTransition
1156// specified by VInfo.
1157void PredTransitions::
1158pushVariant(const TransVariant &VInfo, bool IsRead) {
Andrew Trick9257b8f2012-09-22 02:24:21 +00001159 PredTransition &Trans = TransVec[VInfo.TransVecIdx];
1160
Andrew Trick9257b8f2012-09-22 02:24:21 +00001161 // If this operand transition is reached through a processor-specific alias,
1162 // then the whole transition is specific to this processor.
1163 if (VInfo.ProcIdx != 0)
1164 Trans.ProcIndices.assign(1, VInfo.ProcIdx);
1165
Andrew Trick33401e82012-09-15 00:19:59 +00001166 IdxVec SelectedRWs;
Andrew Trickda984b12012-10-03 23:06:28 +00001167 if (VInfo.VarOrSeqDef->isSubClassOf("SchedVar")) {
1168 Record *PredDef = VInfo.VarOrSeqDef->getValueAsDef("Predicate");
1169 Trans.PredTerm.push_back(PredCheck(IsRead, VInfo.RWIdx,PredDef));
1170 RecVec SelectedDefs = VInfo.VarOrSeqDef->getValueAsListOfDefs("Selected");
1171 SchedModels.findRWs(SelectedDefs, SelectedRWs, IsRead);
1172 }
1173 else {
1174 assert(VInfo.VarOrSeqDef->isSubClassOf("WriteSequence") &&
1175 "variant must be a SchedVariant or aliased WriteSequence");
1176 SelectedRWs.push_back(SchedModels.getSchedRWIdx(VInfo.VarOrSeqDef, IsRead));
1177 }
Andrew Trick33401e82012-09-15 00:19:59 +00001178
Andrew Trick9257b8f2012-09-22 02:24:21 +00001179 const CodeGenSchedRW &SchedRW = SchedModels.getSchedRW(VInfo.RWIdx, IsRead);
Andrew Trick33401e82012-09-15 00:19:59 +00001180
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +00001181 SmallVectorImpl<SmallVector<unsigned,4>> &RWSequences = IsRead
Andrew Trick33401e82012-09-15 00:19:59 +00001182 ? Trans.ReadSequences : Trans.WriteSequences;
1183 if (SchedRW.IsVariadic) {
1184 unsigned OperIdx = RWSequences.size()-1;
1185 // Make N-1 copies of this transition's last sequence.
1186 for (unsigned i = 1, e = SelectedRWs.size(); i != e; ++i) {
Arnold Schwaighofer3bd25242013-06-06 23:23:14 +00001187 // Create a temporary copy the vector could reallocate.
Arnold Schwaighoferf84a03a2013-06-07 00:04:30 +00001188 RWSequences.reserve(RWSequences.size() + 1);
1189 RWSequences.push_back(RWSequences[OperIdx]);
Andrew Trick33401e82012-09-15 00:19:59 +00001190 }
1191 // Push each of the N elements of the SelectedRWs onto a copy of the last
1192 // sequence (split the current operand into N operands).
1193 // Note that write sequences should be expanded within this loop--the entire
1194 // sequence belongs to a single operand.
1195 for (IdxIter RWI = SelectedRWs.begin(), RWE = SelectedRWs.end();
1196 RWI != RWE; ++RWI, ++OperIdx) {
1197 IdxVec ExpandedRWs;
1198 if (IsRead)
1199 ExpandedRWs.push_back(*RWI);
1200 else
1201 SchedModels.expandRWSequence(*RWI, ExpandedRWs, IsRead);
1202 RWSequences[OperIdx].insert(RWSequences[OperIdx].end(),
1203 ExpandedRWs.begin(), ExpandedRWs.end());
1204 }
1205 assert(OperIdx == RWSequences.size() && "missed a sequence");
1206 }
1207 else {
1208 // Push this transition's expanded sequence onto this transition's last
1209 // sequence (add to the current operand's sequence).
1210 SmallVectorImpl<unsigned> &Seq = RWSequences.back();
1211 IdxVec ExpandedRWs;
1212 for (IdxIter RWI = SelectedRWs.begin(), RWE = SelectedRWs.end();
1213 RWI != RWE; ++RWI) {
1214 if (IsRead)
1215 ExpandedRWs.push_back(*RWI);
1216 else
1217 SchedModels.expandRWSequence(*RWI, ExpandedRWs, IsRead);
1218 }
1219 Seq.insert(Seq.end(), ExpandedRWs.begin(), ExpandedRWs.end());
1220 }
1221}
1222
1223// RWSeq is a sequence of all Reads or all Writes for the next read or write
1224// operand. StartIdx is an index into TransVec where partial results
Andrew Trick9257b8f2012-09-22 02:24:21 +00001225// starts. RWSeq must be applied to all transitions between StartIdx and the end
Andrew Trick33401e82012-09-15 00:19:59 +00001226// of TransVec.
1227void PredTransitions::substituteVariantOperand(
1228 const SmallVectorImpl<unsigned> &RWSeq, bool IsRead, unsigned StartIdx) {
1229
1230 // Visit each original RW within the current sequence.
1231 for (SmallVectorImpl<unsigned>::const_iterator
1232 RWI = RWSeq.begin(), RWE = RWSeq.end(); RWI != RWE; ++RWI) {
1233 const CodeGenSchedRW &SchedRW = SchedModels.getSchedRW(*RWI, IsRead);
1234 // Push this RW on all partial PredTransitions or distribute variants.
1235 // New PredTransitions may be pushed within this loop which should not be
1236 // revisited (TransEnd must be loop invariant).
1237 for (unsigned TransIdx = StartIdx, TransEnd = TransVec.size();
1238 TransIdx != TransEnd; ++TransIdx) {
1239 // In the common case, push RW onto the current operand's sequence.
Andrew Trick9257b8f2012-09-22 02:24:21 +00001240 if (!hasAliasedVariants(SchedRW, SchedModels)) {
Andrew Trick33401e82012-09-15 00:19:59 +00001241 if (IsRead)
1242 TransVec[TransIdx].ReadSequences.back().push_back(*RWI);
1243 else
1244 TransVec[TransIdx].WriteSequences.back().push_back(*RWI);
1245 continue;
1246 }
1247 // Distribute this partial PredTransition across intersecting variants.
Andrew Trickda984b12012-10-03 23:06:28 +00001248 // This will push a copies of TransVec[TransIdx] on the back of TransVec.
Andrew Trick9257b8f2012-09-22 02:24:21 +00001249 std::vector<TransVariant> IntersectingVariants;
Andrew Trickda984b12012-10-03 23:06:28 +00001250 getIntersectingVariants(SchedRW, TransIdx, IntersectingVariants);
Andrew Trick33401e82012-09-15 00:19:59 +00001251 // Now expand each variant on top of its copy of the transition.
Andrew Trick9257b8f2012-09-22 02:24:21 +00001252 for (std::vector<TransVariant>::const_iterator
Andrew Trick33401e82012-09-15 00:19:59 +00001253 IVI = IntersectingVariants.begin(),
1254 IVE = IntersectingVariants.end();
Andrew Trick9257b8f2012-09-22 02:24:21 +00001255 IVI != IVE; ++IVI) {
1256 pushVariant(*IVI, IsRead);
1257 }
Andrew Trick33401e82012-09-15 00:19:59 +00001258 }
1259 }
1260}
1261
1262// For each variant of a Read/Write in Trans, substitute the sequence of
1263// Read/Writes guarded by the variant. This is exponential in the number of
1264// variant Read/Writes, but in practice detection of mutually exclusive
1265// predicates should result in linear growth in the total number variants.
1266//
1267// This is one step in a breadth-first search of nested variants.
1268void PredTransitions::substituteVariants(const PredTransition &Trans) {
1269 // Build up a set of partial results starting at the back of
1270 // PredTransitions. Remember the first new transition.
1271 unsigned StartIdx = TransVec.size();
1272 TransVec.resize(TransVec.size() + 1);
1273 TransVec.back().PredTerm = Trans.PredTerm;
Andrew Trick9257b8f2012-09-22 02:24:21 +00001274 TransVec.back().ProcIndices = Trans.ProcIndices;
Andrew Trick33401e82012-09-15 00:19:59 +00001275
1276 // Visit each original write sequence.
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +00001277 for (SmallVectorImpl<SmallVector<unsigned,4>>::const_iterator
Andrew Trick33401e82012-09-15 00:19:59 +00001278 WSI = Trans.WriteSequences.begin(), WSE = Trans.WriteSequences.end();
1279 WSI != WSE; ++WSI) {
1280 // Push a new (empty) write sequence onto all partial Transitions.
1281 for (std::vector<PredTransition>::iterator I =
1282 TransVec.begin() + StartIdx, E = TransVec.end(); I != E; ++I) {
1283 I->WriteSequences.resize(I->WriteSequences.size() + 1);
1284 }
1285 substituteVariantOperand(*WSI, /*IsRead=*/false, StartIdx);
1286 }
1287 // Visit each original read sequence.
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +00001288 for (SmallVectorImpl<SmallVector<unsigned,4>>::const_iterator
Andrew Trick33401e82012-09-15 00:19:59 +00001289 RSI = Trans.ReadSequences.begin(), RSE = Trans.ReadSequences.end();
1290 RSI != RSE; ++RSI) {
1291 // Push a new (empty) read sequence onto all partial Transitions.
1292 for (std::vector<PredTransition>::iterator I =
1293 TransVec.begin() + StartIdx, E = TransVec.end(); I != E; ++I) {
1294 I->ReadSequences.resize(I->ReadSequences.size() + 1);
1295 }
1296 substituteVariantOperand(*RSI, /*IsRead=*/true, StartIdx);
1297 }
1298}
1299
Andrew Trick33401e82012-09-15 00:19:59 +00001300// Create a new SchedClass for each variant found by inferFromRW. Pass
Andrew Trick33401e82012-09-15 00:19:59 +00001301static void inferFromTransitions(ArrayRef<PredTransition> LastTransitions,
Andrew Trick9257b8f2012-09-22 02:24:21 +00001302 unsigned FromClassIdx,
Andrew Trick33401e82012-09-15 00:19:59 +00001303 CodeGenSchedModels &SchedModels) {
1304 // For each PredTransition, create a new CodeGenSchedTransition, which usually
1305 // requires creating a new SchedClass.
1306 for (ArrayRef<PredTransition>::iterator
1307 I = LastTransitions.begin(), E = LastTransitions.end(); I != E; ++I) {
1308 IdxVec OperWritesVariant;
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +00001309 for (SmallVectorImpl<SmallVector<unsigned,4>>::const_iterator
Andrew Trick33401e82012-09-15 00:19:59 +00001310 WSI = I->WriteSequences.begin(), WSE = I->WriteSequences.end();
1311 WSI != WSE; ++WSI) {
1312 // Create a new write representing the expanded sequence.
1313 OperWritesVariant.push_back(
1314 SchedModels.findOrInsertRW(*WSI, /*IsRead=*/false));
1315 }
1316 IdxVec OperReadsVariant;
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +00001317 for (SmallVectorImpl<SmallVector<unsigned,4>>::const_iterator
Andrew Trick33401e82012-09-15 00:19:59 +00001318 RSI = I->ReadSequences.begin(), RSE = I->ReadSequences.end();
1319 RSI != RSE; ++RSI) {
Andrew Trick9257b8f2012-09-22 02:24:21 +00001320 // Create a new read representing the expanded sequence.
Andrew Trick33401e82012-09-15 00:19:59 +00001321 OperReadsVariant.push_back(
1322 SchedModels.findOrInsertRW(*RSI, /*IsRead=*/true));
1323 }
Andrew Trick9257b8f2012-09-22 02:24:21 +00001324 IdxVec ProcIndices(I->ProcIndices.begin(), I->ProcIndices.end());
Andrew Trick33401e82012-09-15 00:19:59 +00001325 CodeGenSchedTransition SCTrans;
1326 SCTrans.ToClassIdx =
Craig Topper24064772014-04-15 07:20:03 +00001327 SchedModels.addSchedClass(/*ItinClassDef=*/nullptr, OperWritesVariant,
Andrew Trickbf8a28d2013-03-16 18:58:55 +00001328 OperReadsVariant, ProcIndices);
Andrew Trick33401e82012-09-15 00:19:59 +00001329 SCTrans.ProcIndices = ProcIndices;
1330 // The final PredTerm is unique set of predicates guarding the transition.
1331 RecVec Preds;
1332 for (SmallVectorImpl<PredCheck>::const_iterator
1333 PI = I->PredTerm.begin(), PE = I->PredTerm.end(); PI != PE; ++PI) {
1334 Preds.push_back(PI->Predicate);
1335 }
1336 RecIter PredsEnd = std::unique(Preds.begin(), Preds.end());
1337 Preds.resize(PredsEnd - Preds.begin());
1338 SCTrans.PredTerm = Preds;
1339 SchedModels.getSchedClass(FromClassIdx).Transitions.push_back(SCTrans);
1340 }
1341}
1342
Andrew Trick9257b8f2012-09-22 02:24:21 +00001343// Create new SchedClasses for the given ReadWrite list. If any of the
1344// ReadWrites refers to a SchedVariant, create a new SchedClass for each variant
1345// of the ReadWrite list, following Aliases if necessary.
Benjamin Kramere1761952015-10-24 12:46:49 +00001346void CodeGenSchedModels::inferFromRW(ArrayRef<unsigned> OperWrites,
1347 ArrayRef<unsigned> OperReads,
Andrew Trick33401e82012-09-15 00:19:59 +00001348 unsigned FromClassIdx,
Benjamin Kramere1761952015-10-24 12:46:49 +00001349 ArrayRef<unsigned> ProcIndices) {
Andrew Tricke97978f2013-03-26 21:36:39 +00001350 DEBUG(dbgs() << "INFER RW proc("; dumpIdxVec(ProcIndices); dbgs() << ") ");
Andrew Trick33401e82012-09-15 00:19:59 +00001351
1352 // Create a seed transition with an empty PredTerm and the expanded sequences
1353 // of SchedWrites for the current SchedClass.
1354 std::vector<PredTransition> LastTransitions;
1355 LastTransitions.resize(1);
Andrew Trick9257b8f2012-09-22 02:24:21 +00001356 LastTransitions.back().ProcIndices.append(ProcIndices.begin(),
1357 ProcIndices.end());
1358
Benjamin Kramere1761952015-10-24 12:46:49 +00001359 for (unsigned WriteIdx : OperWrites) {
Andrew Trick33401e82012-09-15 00:19:59 +00001360 IdxVec WriteSeq;
Benjamin Kramere1761952015-10-24 12:46:49 +00001361 expandRWSequence(WriteIdx, WriteSeq, /*IsRead=*/false);
Andrew Trick33401e82012-09-15 00:19:59 +00001362 unsigned Idx = LastTransitions[0].WriteSequences.size();
1363 LastTransitions[0].WriteSequences.resize(Idx + 1);
1364 SmallVectorImpl<unsigned> &Seq = LastTransitions[0].WriteSequences[Idx];
1365 for (IdxIter WI = WriteSeq.begin(), WE = WriteSeq.end(); WI != WE; ++WI)
1366 Seq.push_back(*WI);
1367 DEBUG(dbgs() << "("; dumpIdxVec(Seq); dbgs() << ") ");
1368 }
1369 DEBUG(dbgs() << " Reads: ");
Benjamin Kramere1761952015-10-24 12:46:49 +00001370 for (unsigned ReadIdx : OperReads) {
Andrew Trick33401e82012-09-15 00:19:59 +00001371 IdxVec ReadSeq;
Benjamin Kramere1761952015-10-24 12:46:49 +00001372 expandRWSequence(ReadIdx, ReadSeq, /*IsRead=*/true);
Andrew Trick33401e82012-09-15 00:19:59 +00001373 unsigned Idx = LastTransitions[0].ReadSequences.size();
1374 LastTransitions[0].ReadSequences.resize(Idx + 1);
1375 SmallVectorImpl<unsigned> &Seq = LastTransitions[0].ReadSequences[Idx];
1376 for (IdxIter RI = ReadSeq.begin(), RE = ReadSeq.end(); RI != RE; ++RI)
1377 Seq.push_back(*RI);
1378 DEBUG(dbgs() << "("; dumpIdxVec(Seq); dbgs() << ") ");
1379 }
1380 DEBUG(dbgs() << '\n');
1381
1382 // Collect all PredTransitions for individual operands.
1383 // Iterate until no variant writes remain.
1384 while (hasVariant(LastTransitions, *this)) {
1385 PredTransitions Transitions(*this);
1386 for (std::vector<PredTransition>::const_iterator
1387 I = LastTransitions.begin(), E = LastTransitions.end();
1388 I != E; ++I) {
1389 Transitions.substituteVariants(*I);
1390 }
1391 DEBUG(Transitions.dump());
1392 LastTransitions.swap(Transitions.TransVec);
1393 }
1394 // If the first transition has no variants, nothing to do.
1395 if (LastTransitions[0].PredTerm.empty())
1396 return;
1397
1398 // WARNING: We are about to mutate the SchedClasses vector. Do not refer to
1399 // OperWrites, OperReads, or ProcIndices after calling inferFromTransitions.
Andrew Trick9257b8f2012-09-22 02:24:21 +00001400 inferFromTransitions(LastTransitions, FromClassIdx, *this);
Andrew Trick33401e82012-09-15 00:19:59 +00001401}
1402
Andrew Trickcf398b22013-04-23 23:45:14 +00001403// Check if any processor resource group contains all resource records in
1404// SubUnits.
1405bool CodeGenSchedModels::hasSuperGroup(RecVec &SubUnits, CodeGenProcModel &PM) {
1406 for (unsigned i = 0, e = PM.ProcResourceDefs.size(); i < e; ++i) {
1407 if (!PM.ProcResourceDefs[i]->isSubClassOf("ProcResGroup"))
1408 continue;
1409 RecVec SuperUnits =
1410 PM.ProcResourceDefs[i]->getValueAsListOfDefs("Resources");
1411 RecIter RI = SubUnits.begin(), RE = SubUnits.end();
1412 for ( ; RI != RE; ++RI) {
David Majnemer0d955d02016-08-11 22:21:41 +00001413 if (!is_contained(SuperUnits, *RI)) {
Andrew Trickcf398b22013-04-23 23:45:14 +00001414 break;
1415 }
1416 }
1417 if (RI == RE)
1418 return true;
1419 }
1420 return false;
1421}
1422
1423// Verify that overlapping groups have a common supergroup.
1424void CodeGenSchedModels::verifyProcResourceGroups(CodeGenProcModel &PM) {
1425 for (unsigned i = 0, e = PM.ProcResourceDefs.size(); i < e; ++i) {
1426 if (!PM.ProcResourceDefs[i]->isSubClassOf("ProcResGroup"))
1427 continue;
1428 RecVec CheckUnits =
1429 PM.ProcResourceDefs[i]->getValueAsListOfDefs("Resources");
1430 for (unsigned j = i+1; j < e; ++j) {
1431 if (!PM.ProcResourceDefs[j]->isSubClassOf("ProcResGroup"))
1432 continue;
1433 RecVec OtherUnits =
1434 PM.ProcResourceDefs[j]->getValueAsListOfDefs("Resources");
1435 if (std::find_first_of(CheckUnits.begin(), CheckUnits.end(),
1436 OtherUnits.begin(), OtherUnits.end())
1437 != CheckUnits.end()) {
1438 // CheckUnits and OtherUnits overlap
1439 OtherUnits.insert(OtherUnits.end(), CheckUnits.begin(),
1440 CheckUnits.end());
1441 if (!hasSuperGroup(OtherUnits, PM)) {
1442 PrintFatalError((PM.ProcResourceDefs[i])->getLoc(),
1443 "proc resource group overlaps with "
1444 + PM.ProcResourceDefs[j]->getName()
1445 + " but no supergroup contains both.");
1446 }
1447 }
1448 }
1449 }
1450}
1451
Andrew Trick1e46d482012-09-15 00:20:02 +00001452// Collect and sort WriteRes, ReadAdvance, and ProcResources.
1453void CodeGenSchedModels::collectProcResources() {
Matthias Braun6b1fd9a2016-06-21 03:24:03 +00001454 ProcResourceDefs = Records.getAllDerivedDefinitions("ProcResourceUnits");
1455 ProcResGroups = Records.getAllDerivedDefinitions("ProcResGroup");
1456
Andrew Trick1e46d482012-09-15 00:20:02 +00001457 // Add any subtarget-specific SchedReadWrites that are directly associated
1458 // with processor resources. Refer to the parent SchedClass's ProcIndices to
1459 // determine which processors they apply to.
1460 for (SchedClassIter SCI = schedClassBegin(), SCE = schedClassEnd();
1461 SCI != SCE; ++SCI) {
1462 if (SCI->ItinClassDef)
1463 collectItinProcResources(SCI->ItinClassDef);
Andrew Trick4fe440d2013-02-01 03:19:54 +00001464 else {
1465 // This class may have a default ReadWrite list which can be overriden by
1466 // InstRW definitions.
1467 if (!SCI->InstRWs.empty()) {
1468 for (RecIter RWI = SCI->InstRWs.begin(), RWE = SCI->InstRWs.end();
1469 RWI != RWE; ++RWI) {
1470 Record *RWModelDef = (*RWI)->getValueAsDef("SchedModel");
1471 IdxVec ProcIndices(1, getProcModel(RWModelDef).Index);
1472 IdxVec Writes, Reads;
1473 findRWs((*RWI)->getValueAsListOfDefs("OperandReadWrites"),
1474 Writes, Reads);
1475 collectRWResources(Writes, Reads, ProcIndices);
1476 }
1477 }
Andrew Trick1e46d482012-09-15 00:20:02 +00001478 collectRWResources(SCI->Writes, SCI->Reads, SCI->ProcIndices);
Andrew Trick4fe440d2013-02-01 03:19:54 +00001479 }
Andrew Trick1e46d482012-09-15 00:20:02 +00001480 }
1481 // Add resources separately defined by each subtarget.
1482 RecVec WRDefs = Records.getAllDerivedDefinitions("WriteRes");
1483 for (RecIter WRI = WRDefs.begin(), WRE = WRDefs.end(); WRI != WRE; ++WRI) {
1484 Record *ModelDef = (*WRI)->getValueAsDef("SchedModel");
1485 addWriteRes(*WRI, getProcModel(ModelDef).Index);
1486 }
Andrew Trickdca870b2014-03-13 03:49:20 +00001487 RecVec SWRDefs = Records.getAllDerivedDefinitions("SchedWriteRes");
1488 for (RecIter WRI = SWRDefs.begin(), WRE = SWRDefs.end(); WRI != WRE; ++WRI) {
1489 Record *ModelDef = (*WRI)->getValueAsDef("SchedModel");
1490 addWriteRes(*WRI, getProcModel(ModelDef).Index);
1491 }
Andrew Trick1e46d482012-09-15 00:20:02 +00001492 RecVec RADefs = Records.getAllDerivedDefinitions("ReadAdvance");
1493 for (RecIter RAI = RADefs.begin(), RAE = RADefs.end(); RAI != RAE; ++RAI) {
1494 Record *ModelDef = (*RAI)->getValueAsDef("SchedModel");
1495 addReadAdvance(*RAI, getProcModel(ModelDef).Index);
1496 }
Andrew Trickdca870b2014-03-13 03:49:20 +00001497 RecVec SRADefs = Records.getAllDerivedDefinitions("SchedReadAdvance");
1498 for (RecIter RAI = SRADefs.begin(), RAE = SRADefs.end(); RAI != RAE; ++RAI) {
1499 if ((*RAI)->getValueInit("SchedModel")->isComplete()) {
1500 Record *ModelDef = (*RAI)->getValueAsDef("SchedModel");
1501 addReadAdvance(*RAI, getProcModel(ModelDef).Index);
1502 }
1503 }
Andrew Trick40c4f382013-06-15 04:50:06 +00001504 // Add ProcResGroups that are defined within this processor model, which may
1505 // not be directly referenced but may directly specify a buffer size.
1506 RecVec ProcResGroups = Records.getAllDerivedDefinitions("ProcResGroup");
Javed Absarfc500042017-10-05 13:27:43 +00001507 for (Record *PRG : make_range(ProcResGroups.begin(), ProcResGroups.end())) {
1508 if (!PRG->getValueInit("SchedModel")->isComplete())
Andrew Trick40c4f382013-06-15 04:50:06 +00001509 continue;
Javed Absarfc500042017-10-05 13:27:43 +00001510 CodeGenProcModel &PM = getProcModel(PRG->getValueAsDef("SchedModel"));
1511 if (!is_contained(PM.ProcResourceDefs, PRG))
1512 PM.ProcResourceDefs.push_back(PRG);
Andrew Trick40c4f382013-06-15 04:50:06 +00001513 }
Andrew Trick1e46d482012-09-15 00:20:02 +00001514 // Finalize each ProcModel by sorting the record arrays.
Craig Topper8a417c12014-12-09 08:05:51 +00001515 for (CodeGenProcModel &PM : ProcModels) {
Andrew Trick1e46d482012-09-15 00:20:02 +00001516 std::sort(PM.WriteResDefs.begin(), PM.WriteResDefs.end(),
1517 LessRecord());
1518 std::sort(PM.ReadAdvanceDefs.begin(), PM.ReadAdvanceDefs.end(),
1519 LessRecord());
1520 std::sort(PM.ProcResourceDefs.begin(), PM.ProcResourceDefs.end(),
1521 LessRecord());
1522 DEBUG(
1523 PM.dump();
1524 dbgs() << "WriteResDefs: ";
1525 for (RecIter RI = PM.WriteResDefs.begin(),
1526 RE = PM.WriteResDefs.end(); RI != RE; ++RI) {
1527 if ((*RI)->isSubClassOf("WriteRes"))
1528 dbgs() << (*RI)->getValueAsDef("WriteType")->getName() << " ";
1529 else
1530 dbgs() << (*RI)->getName() << " ";
1531 }
1532 dbgs() << "\nReadAdvanceDefs: ";
1533 for (RecIter RI = PM.ReadAdvanceDefs.begin(),
1534 RE = PM.ReadAdvanceDefs.end(); RI != RE; ++RI) {
1535 if ((*RI)->isSubClassOf("ReadAdvance"))
1536 dbgs() << (*RI)->getValueAsDef("ReadType")->getName() << " ";
1537 else
1538 dbgs() << (*RI)->getName() << " ";
1539 }
1540 dbgs() << "\nProcResourceDefs: ";
1541 for (RecIter RI = PM.ProcResourceDefs.begin(),
1542 RE = PM.ProcResourceDefs.end(); RI != RE; ++RI) {
1543 dbgs() << (*RI)->getName() << " ";
1544 }
1545 dbgs() << '\n');
Andrew Trickcf398b22013-04-23 23:45:14 +00001546 verifyProcResourceGroups(PM);
Andrew Trick1e46d482012-09-15 00:20:02 +00001547 }
Matthias Braun6b1fd9a2016-06-21 03:24:03 +00001548
1549 ProcResourceDefs.clear();
1550 ProcResGroups.clear();
Andrew Trick1e46d482012-09-15 00:20:02 +00001551}
1552
Matthias Braun17cb5792016-03-01 20:03:21 +00001553void CodeGenSchedModels::checkCompleteness() {
1554 bool Complete = true;
1555 bool HadCompleteModel = false;
1556 for (const CodeGenProcModel &ProcModel : procModels()) {
Matthias Braun17cb5792016-03-01 20:03:21 +00001557 if (!ProcModel.ModelDef->getValueAsBit("CompleteModel"))
1558 continue;
1559 for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) {
1560 if (Inst->hasNoSchedulingInfo)
1561 continue;
Simon Dardis5f95c9a2016-06-24 08:43:27 +00001562 if (ProcModel.isUnsupported(*Inst))
1563 continue;
Matthias Braun17cb5792016-03-01 20:03:21 +00001564 unsigned SCIdx = getSchedClassIdx(*Inst);
1565 if (!SCIdx) {
1566 if (Inst->TheDef->isValueUnset("SchedRW") && !HadCompleteModel) {
1567 PrintError("No schedule information for instruction '"
1568 + Inst->TheDef->getName() + "'");
1569 Complete = false;
1570 }
1571 continue;
1572 }
1573
1574 const CodeGenSchedClass &SC = getSchedClass(SCIdx);
1575 if (!SC.Writes.empty())
1576 continue;
Ulrich Weigand75cda2f2016-10-31 18:59:52 +00001577 if (SC.ItinClassDef != nullptr &&
1578 SC.ItinClassDef->getName() != "NoItinerary")
Matthias Braun42d9ad92016-03-03 00:04:59 +00001579 continue;
Matthias Braun17cb5792016-03-01 20:03:21 +00001580
1581 const RecVec &InstRWs = SC.InstRWs;
David Majnemer562e8292016-08-12 00:18:03 +00001582 auto I = find_if(InstRWs, [&ProcModel](const Record *R) {
1583 return R->getValueAsDef("SchedModel") == ProcModel.ModelDef;
1584 });
Matthias Braun17cb5792016-03-01 20:03:21 +00001585 if (I == InstRWs.end()) {
1586 PrintError("'" + ProcModel.ModelName + "' lacks information for '" +
1587 Inst->TheDef->getName() + "'");
1588 Complete = false;
1589 }
1590 }
1591 HadCompleteModel = true;
1592 }
Matthias Brauna939bd02016-03-01 21:36:12 +00001593 if (!Complete) {
1594 errs() << "\n\nIncomplete schedule models found.\n"
1595 << "- Consider setting 'CompleteModel = 0' while developing new models.\n"
1596 << "- Pseudo instructions can be marked with 'hasNoSchedulingInfo = 1'.\n"
1597 << "- Instructions should usually have Sched<[...]> as a superclass, "
Simon Dardis5f95c9a2016-06-24 08:43:27 +00001598 "you may temporarily use an empty list.\n"
1599 << "- Instructions related to unsupported features can be excluded with "
1600 "list<Predicate> UnsupportedFeatures = [HasA,..,HasY]; in the "
1601 "processor model.\n\n";
Matthias Braun17cb5792016-03-01 20:03:21 +00001602 PrintFatalError("Incomplete schedule model");
Matthias Brauna939bd02016-03-01 21:36:12 +00001603 }
Matthias Braun17cb5792016-03-01 20:03:21 +00001604}
1605
Andrew Trick1e46d482012-09-15 00:20:02 +00001606// Collect itinerary class resources for each processor.
1607void CodeGenSchedModels::collectItinProcResources(Record *ItinClassDef) {
1608 for (unsigned PIdx = 0, PEnd = ProcModels.size(); PIdx != PEnd; ++PIdx) {
1609 const CodeGenProcModel &PM = ProcModels[PIdx];
1610 // For all ItinRW entries.
1611 bool HasMatch = false;
1612 for (RecIter II = PM.ItinRWDefs.begin(), IE = PM.ItinRWDefs.end();
1613 II != IE; ++II) {
1614 RecVec Matched = (*II)->getValueAsListOfDefs("MatchedItinClasses");
1615 if (!std::count(Matched.begin(), Matched.end(), ItinClassDef))
1616 continue;
1617 if (HasMatch)
Joerg Sonnenberger635debe2012-10-25 20:33:17 +00001618 PrintFatalError((*II)->getLoc(), "Duplicate itinerary class "
1619 + ItinClassDef->getName()
1620 + " in ItinResources for " + PM.ModelName);
Andrew Trick1e46d482012-09-15 00:20:02 +00001621 HasMatch = true;
1622 IdxVec Writes, Reads;
1623 findRWs((*II)->getValueAsListOfDefs("OperandReadWrites"), Writes, Reads);
1624 IdxVec ProcIndices(1, PIdx);
1625 collectRWResources(Writes, Reads, ProcIndices);
1626 }
1627 }
1628}
1629
Andrew Trickd0b9c442012-10-10 05:43:13 +00001630void CodeGenSchedModels::collectRWResources(unsigned RWIdx, bool IsRead,
Benjamin Kramere1761952015-10-24 12:46:49 +00001631 ArrayRef<unsigned> ProcIndices) {
Andrew Trickd0b9c442012-10-10 05:43:13 +00001632 const CodeGenSchedRW &SchedRW = getSchedRW(RWIdx, IsRead);
1633 if (SchedRW.TheDef) {
1634 if (!IsRead && SchedRW.TheDef->isSubClassOf("SchedWriteRes")) {
Benjamin Kramere1761952015-10-24 12:46:49 +00001635 for (unsigned Idx : ProcIndices)
1636 addWriteRes(SchedRW.TheDef, Idx);
Andrew Trickd0b9c442012-10-10 05:43:13 +00001637 }
1638 else if (IsRead && SchedRW.TheDef->isSubClassOf("SchedReadAdvance")) {
Benjamin Kramere1761952015-10-24 12:46:49 +00001639 for (unsigned Idx : ProcIndices)
1640 addReadAdvance(SchedRW.TheDef, Idx);
Andrew Trickd0b9c442012-10-10 05:43:13 +00001641 }
1642 }
1643 for (RecIter AI = SchedRW.Aliases.begin(), AE = SchedRW.Aliases.end();
1644 AI != AE; ++AI) {
1645 IdxVec AliasProcIndices;
1646 if ((*AI)->getValueInit("SchedModel")->isComplete()) {
1647 AliasProcIndices.push_back(
1648 getProcModel((*AI)->getValueAsDef("SchedModel")).Index);
1649 }
1650 else
1651 AliasProcIndices = ProcIndices;
1652 const CodeGenSchedRW &AliasRW = getSchedRW((*AI)->getValueAsDef("AliasRW"));
1653 assert(AliasRW.IsRead == IsRead && "cannot alias reads to writes");
1654
1655 IdxVec ExpandedRWs;
1656 expandRWSequence(AliasRW.Index, ExpandedRWs, IsRead);
1657 for (IdxIter SI = ExpandedRWs.begin(), SE = ExpandedRWs.end();
1658 SI != SE; ++SI) {
1659 collectRWResources(*SI, IsRead, AliasProcIndices);
1660 }
1661 }
1662}
Andrew Trick1e46d482012-09-15 00:20:02 +00001663
1664// Collect resources for a set of read/write types and processor indices.
Benjamin Kramere1761952015-10-24 12:46:49 +00001665void CodeGenSchedModels::collectRWResources(ArrayRef<unsigned> Writes,
1666 ArrayRef<unsigned> Reads,
1667 ArrayRef<unsigned> ProcIndices) {
Benjamin Kramere1761952015-10-24 12:46:49 +00001668 for (unsigned Idx : Writes)
1669 collectRWResources(Idx, /*IsRead=*/false, ProcIndices);
Andrew Trickd0b9c442012-10-10 05:43:13 +00001670
Benjamin Kramere1761952015-10-24 12:46:49 +00001671 for (unsigned Idx : Reads)
1672 collectRWResources(Idx, /*IsRead=*/true, ProcIndices);
Andrew Trick1e46d482012-09-15 00:20:02 +00001673}
1674
1675// Find the processor's resource units for this kind of resource.
1676Record *CodeGenSchedModels::findProcResUnits(Record *ProcResKind,
1677 const CodeGenProcModel &PM) const {
1678 if (ProcResKind->isSubClassOf("ProcResourceUnits"))
1679 return ProcResKind;
1680
Craig Topper24064772014-04-15 07:20:03 +00001681 Record *ProcUnitDef = nullptr;
Matthias Braun6b1fd9a2016-06-21 03:24:03 +00001682 assert(!ProcResourceDefs.empty());
1683 assert(!ProcResGroups.empty());
Andrew Trick1e46d482012-09-15 00:20:02 +00001684
Javed Absar67b042c2017-09-13 10:31:10 +00001685 for (Record *ProcResDef : ProcResourceDefs) {
1686 if (ProcResDef->getValueAsDef("Kind") == ProcResKind
1687 && ProcResDef->getValueAsDef("SchedModel") == PM.ModelDef) {
Andrew Trick1e46d482012-09-15 00:20:02 +00001688 if (ProcUnitDef) {
Javed Absar67b042c2017-09-13 10:31:10 +00001689 PrintFatalError(ProcResDef->getLoc(),
Joerg Sonnenberger635debe2012-10-25 20:33:17 +00001690 "Multiple ProcessorResourceUnits associated with "
1691 + ProcResKind->getName());
Andrew Trick1e46d482012-09-15 00:20:02 +00001692 }
Javed Absar67b042c2017-09-13 10:31:10 +00001693 ProcUnitDef = ProcResDef;
Andrew Trick1e46d482012-09-15 00:20:02 +00001694 }
1695 }
Javed Absar67b042c2017-09-13 10:31:10 +00001696 for (Record *ProcResGroup : ProcResGroups) {
1697 if (ProcResGroup == ProcResKind
1698 && ProcResGroup->getValueAsDef("SchedModel") == PM.ModelDef) {
Andrew Trick4e67cba2013-03-14 21:21:50 +00001699 if (ProcUnitDef) {
Javed Absar67b042c2017-09-13 10:31:10 +00001700 PrintFatalError((ProcResGroup)->getLoc(),
Andrew Trick4e67cba2013-03-14 21:21:50 +00001701 "Multiple ProcessorResourceUnits associated with "
1702 + ProcResKind->getName());
1703 }
Javed Absar67b042c2017-09-13 10:31:10 +00001704 ProcUnitDef = ProcResGroup;
Andrew Trick4e67cba2013-03-14 21:21:50 +00001705 }
1706 }
Andrew Trick1e46d482012-09-15 00:20:02 +00001707 if (!ProcUnitDef) {
Joerg Sonnenberger635debe2012-10-25 20:33:17 +00001708 PrintFatalError(ProcResKind->getLoc(),
1709 "No ProcessorResources associated with "
1710 + ProcResKind->getName());
Andrew Trick1e46d482012-09-15 00:20:02 +00001711 }
1712 return ProcUnitDef;
1713}
1714
1715// Iteratively add a resource and its super resources.
1716void CodeGenSchedModels::addProcResource(Record *ProcResKind,
1717 CodeGenProcModel &PM) {
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +00001718 while (true) {
Andrew Trick1e46d482012-09-15 00:20:02 +00001719 Record *ProcResUnits = findProcResUnits(ProcResKind, PM);
1720
1721 // See if this ProcResource is already associated with this processor.
David Majnemer42531262016-08-12 03:55:06 +00001722 if (is_contained(PM.ProcResourceDefs, ProcResUnits))
Andrew Trick1e46d482012-09-15 00:20:02 +00001723 return;
1724
1725 PM.ProcResourceDefs.push_back(ProcResUnits);
Andrew Trick4e67cba2013-03-14 21:21:50 +00001726 if (ProcResUnits->isSubClassOf("ProcResGroup"))
1727 return;
1728
Andrew Trick1e46d482012-09-15 00:20:02 +00001729 if (!ProcResUnits->getValueInit("Super")->isComplete())
1730 return;
1731
1732 ProcResKind = ProcResUnits->getValueAsDef("Super");
1733 }
1734}
1735
1736// Add resources for a SchedWrite to this processor if they don't exist.
1737void CodeGenSchedModels::addWriteRes(Record *ProcWriteResDef, unsigned PIdx) {
Andrew Trick9257b8f2012-09-22 02:24:21 +00001738 assert(PIdx && "don't add resources to an invalid Processor model");
1739
Andrew Trick1e46d482012-09-15 00:20:02 +00001740 RecVec &WRDefs = ProcModels[PIdx].WriteResDefs;
David Majnemer42531262016-08-12 03:55:06 +00001741 if (is_contained(WRDefs, ProcWriteResDef))
Andrew Trick1e46d482012-09-15 00:20:02 +00001742 return;
1743 WRDefs.push_back(ProcWriteResDef);
1744
1745 // Visit ProcResourceKinds referenced by the newly discovered WriteRes.
1746 RecVec ProcResDefs = ProcWriteResDef->getValueAsListOfDefs("ProcResources");
1747 for (RecIter WritePRI = ProcResDefs.begin(), WritePRE = ProcResDefs.end();
1748 WritePRI != WritePRE; ++WritePRI) {
1749 addProcResource(*WritePRI, ProcModels[PIdx]);
1750 }
1751}
1752
1753// Add resources for a ReadAdvance to this processor if they don't exist.
1754void CodeGenSchedModels::addReadAdvance(Record *ProcReadAdvanceDef,
1755 unsigned PIdx) {
1756 RecVec &RADefs = ProcModels[PIdx].ReadAdvanceDefs;
David Majnemer42531262016-08-12 03:55:06 +00001757 if (is_contained(RADefs, ProcReadAdvanceDef))
Andrew Trick1e46d482012-09-15 00:20:02 +00001758 return;
1759 RADefs.push_back(ProcReadAdvanceDef);
1760}
1761
Andrew Trick8fa00f52012-09-17 22:18:43 +00001762unsigned CodeGenProcModel::getProcResourceIdx(Record *PRDef) const {
David Majnemer0d955d02016-08-11 22:21:41 +00001763 RecIter PRPos = find(ProcResourceDefs, PRDef);
Andrew Trick8fa00f52012-09-17 22:18:43 +00001764 if (PRPos == ProcResourceDefs.end())
Joerg Sonnenberger635debe2012-10-25 20:33:17 +00001765 PrintFatalError(PRDef->getLoc(), "ProcResource def is not included in "
1766 "the ProcResources list for " + ModelName);
Andrew Trick8fa00f52012-09-17 22:18:43 +00001767 // Idx=0 is reserved for invalid.
Rafael Espindola72961392012-11-02 20:57:36 +00001768 return 1 + (PRPos - ProcResourceDefs.begin());
Andrew Trick8fa00f52012-09-17 22:18:43 +00001769}
1770
Simon Dardis5f95c9a2016-06-24 08:43:27 +00001771bool CodeGenProcModel::isUnsupported(const CodeGenInstruction &Inst) const {
1772 for (const Record *TheDef : UnsupportedFeaturesDefs) {
1773 for (const Record *PredDef : Inst.TheDef->getValueAsListOfDefs("Predicates")) {
1774 if (TheDef->getName() == PredDef->getName())
1775 return true;
1776 }
1777 }
1778 return false;
1779}
1780
Andrew Trick76686492012-09-15 00:19:57 +00001781#ifndef NDEBUG
1782void CodeGenProcModel::dump() const {
1783 dbgs() << Index << ": " << ModelName << " "
1784 << (ModelDef ? ModelDef->getName() : "inferred") << " "
1785 << (ItinsDef ? ItinsDef->getName() : "no itinerary") << '\n';
1786}
1787
1788void CodeGenSchedRW::dump() const {
1789 dbgs() << Name << (IsVariadic ? " (V) " : " ");
1790 if (IsSequence) {
1791 dbgs() << "(";
1792 dumpIdxVec(Sequence);
1793 dbgs() << ")";
1794 }
1795}
1796
1797void CodeGenSchedClass::dump(const CodeGenSchedModels* SchedModels) const {
Andrew Trickbf8a28d2013-03-16 18:58:55 +00001798 dbgs() << "SCHEDCLASS " << Index << ":" << Name << '\n'
Andrew Trick76686492012-09-15 00:19:57 +00001799 << " Writes: ";
1800 for (unsigned i = 0, N = Writes.size(); i < N; ++i) {
1801 SchedModels->getSchedWrite(Writes[i]).dump();
1802 if (i < N-1) {
1803 dbgs() << '\n';
1804 dbgs().indent(10);
1805 }
1806 }
1807 dbgs() << "\n Reads: ";
1808 for (unsigned i = 0, N = Reads.size(); i < N; ++i) {
1809 SchedModels->getSchedRead(Reads[i]).dump();
1810 if (i < N-1) {
1811 dbgs() << '\n';
1812 dbgs().indent(10);
1813 }
1814 }
1815 dbgs() << "\n ProcIdx: "; dumpIdxVec(ProcIndices); dbgs() << '\n';
Andrew Tricke97978f2013-03-26 21:36:39 +00001816 if (!Transitions.empty()) {
1817 dbgs() << "\n Transitions for Proc ";
Javed Absar67b042c2017-09-13 10:31:10 +00001818 for (const CodeGenSchedTransition &Transition : Transitions) {
1819 dumpIdxVec(Transition.ProcIndices);
Andrew Tricke97978f2013-03-26 21:36:39 +00001820 }
1821 }
Andrew Trick76686492012-09-15 00:19:57 +00001822}
Andrew Trick33401e82012-09-15 00:19:59 +00001823
1824void PredTransitions::dump() const {
1825 dbgs() << "Expanded Variants:\n";
1826 for (std::vector<PredTransition>::const_iterator
1827 TI = TransVec.begin(), TE = TransVec.end(); TI != TE; ++TI) {
1828 dbgs() << "{";
1829 for (SmallVectorImpl<PredCheck>::const_iterator
1830 PCI = TI->PredTerm.begin(), PCE = TI->PredTerm.end();
1831 PCI != PCE; ++PCI) {
1832 if (PCI != TI->PredTerm.begin())
1833 dbgs() << ", ";
1834 dbgs() << SchedModels.getSchedRW(PCI->RWIdx, PCI->IsRead).Name
1835 << ":" << PCI->Predicate->getName();
1836 }
1837 dbgs() << "},\n => {";
Eugene Zelenkoa3fe70d2016-11-30 17:48:10 +00001838 for (SmallVectorImpl<SmallVector<unsigned,4>>::const_iterator
Andrew Trick33401e82012-09-15 00:19:59 +00001839 WSI = TI->WriteSequences.begin(), WSE = TI->WriteSequences.end();
1840 WSI != WSE; ++WSI) {
1841 dbgs() << "(";
1842 for (SmallVectorImpl<unsigned>::const_iterator
1843 WI = WSI->begin(), WE = WSI->end(); WI != WE; ++WI) {
1844 if (WI != WSI->begin())
1845 dbgs() << ", ";
1846 dbgs() << SchedModels.getSchedWrite(*WI).Name;
1847 }
1848 dbgs() << "),";
1849 }
1850 dbgs() << "}\n";
1851 }
1852}
Andrew Trick76686492012-09-15 00:19:57 +00001853#endif // NDEBUG