1 //===- CodeGenSchedule.h - Scheduling Machine Models ------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines structures to encapsulate the machine model as described in
10 // the target description.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_UTILS_TABLEGEN_CODEGENSCHEDULE_H
15 #define LLVM_UTILS_TABLEGEN_CODEGENSCHEDULE_H
16 
17 #include "llvm/ADT/APInt.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/TableGen/Record.h"
21 #include "llvm/TableGen/SetTheory.h"
22 
23 namespace llvm {
24 
25 class CodeGenTarget;
26 class CodeGenSchedModels;
27 class CodeGenInstruction;
28 
29 using RecVec = std::vector<Record*>;
30 using RecIter = std::vector<Record*>::const_iterator;
31 
32 using IdxVec = std::vector<unsigned>;
33 using IdxIter = std::vector<unsigned>::const_iterator;
34 
35 /// We have two kinds of SchedReadWrites. Explicitly defined and inferred
36 /// sequences.  TheDef is nonnull for explicit SchedWrites, but Sequence may or
37 /// may not be empty. TheDef is null for inferred sequences, and Sequence must
38 /// be nonempty.
39 ///
40 /// IsVariadic controls whether the variants are expanded into multiple operands
41 /// or a sequence of writes on one operand.
42 struct CodeGenSchedRW {
43   unsigned Index;
44   std::string Name;
45   Record *TheDef;
46   bool IsRead;
47   bool IsAlias;
48   bool HasVariants;
49   bool IsVariadic;
50   bool IsSequence;
51   IdxVec Sequence;
52   RecVec Aliases;
53 
54   CodeGenSchedRW()
55     : Index(0), TheDef(nullptr), IsRead(false), IsAlias(false),
56       HasVariants(false), IsVariadic(false), IsSequence(false) {}
57   CodeGenSchedRW(unsigned Idx, Record *Def)
58     : Index(Idx), TheDef(Def), IsAlias(false), IsVariadic(false) {
59     Name = std::string(Def->getName());
60     IsRead = Def->isSubClassOf("SchedRead");
61     HasVariants = Def->isSubClassOf("SchedVariant");
62     if (HasVariants)
63       IsVariadic = Def->getValueAsBit("Variadic");
64 
65     // Read records don't currently have sequences, but it can be easily
66     // added. Note that implicit Reads (from ReadVariant) may have a Sequence
67     // (but no record).
68     IsSequence = Def->isSubClassOf("WriteSequence");
69   }
70 
71   CodeGenSchedRW(unsigned Idx, bool Read, ArrayRef<unsigned> Seq,
72                  const std::string &Name)
73       : Index(Idx), Name(Name), TheDef(nullptr), IsRead(Read), IsAlias(false),
74         HasVariants(false), IsVariadic(false), IsSequence(true), Sequence(Seq) {
75     assert(Sequence.size() > 1 && "implied sequence needs >1 RWs");
76   }
77 
78   bool isValid() const {
79     assert((!HasVariants || TheDef) && "Variant write needs record def");
80     assert((!IsVariadic || HasVariants) && "Variadic write needs variants");
81     assert((!IsSequence || !HasVariants) && "Sequence can't have variant");
82     assert((!IsSequence || !Sequence.empty()) && "Sequence should be nonempty");
83     assert((!IsAlias || Aliases.empty()) && "Alias cannot have aliases");
84     return TheDef || !Sequence.empty();
85   }
86 
87 #ifndef NDEBUG
88   void dump() const;
89 #endif
90 };
91 
92 /// Represent a transition between SchedClasses induced by SchedVariant.
93 struct CodeGenSchedTransition {
94   unsigned ToClassIdx;
95   unsigned ProcIndex;
96   RecVec PredTerm;
97 };
98 
99 /// Scheduling class.
100 ///
101 /// Each instruction description will be mapped to a scheduling class. There are
102 /// four types of classes:
103 ///
104 /// 1) An explicitly defined itinerary class with ItinClassDef set.
105 /// Writes and ReadDefs are empty. ProcIndices contains 0 for any processor.
106 ///
107 /// 2) An implied class with a list of SchedWrites and SchedReads that are
108 /// defined in an instruction definition and which are common across all
109 /// subtargets. ProcIndices contains 0 for any processor.
110 ///
111 /// 3) An implied class with a list of InstRW records that map instructions to
112 /// SchedWrites and SchedReads per-processor. InstrClassMap should map the same
113 /// instructions to this class. ProcIndices contains all the processors that
114 /// provided InstrRW records for this class. ItinClassDef or Writes/Reads may
115 /// still be defined for processors with no InstRW entry.
116 ///
117 /// 4) An inferred class represents a variant of another class that may be
118 /// resolved at runtime. ProcIndices contains the set of processors that may
119 /// require the class. ProcIndices are propagated through SchedClasses as
120 /// variants are expanded. Multiple SchedClasses may be inferred from an
121 /// itinerary class. Each inherits the processor index from the ItinRW record
122 /// that mapped the itinerary class to the variant Writes or Reads.
123 struct CodeGenSchedClass {
124   unsigned Index;
125   std::string Name;
126   Record *ItinClassDef;
127 
128   IdxVec Writes;
129   IdxVec Reads;
130   // Sorted list of ProcIdx, where ProcIdx==0 implies any processor.
131   IdxVec ProcIndices;
132 
133   std::vector<CodeGenSchedTransition> Transitions;
134 
135   // InstRW records associated with this class. These records may refer to an
136   // Instruction no longer mapped to this class by InstrClassMap. These
137   // Instructions should be ignored by this class because they have been split
138   // off to join another inferred class.
139   RecVec InstRWs;
140   // InstRWs processor indices. Filled in inferFromInstRWs
141   DenseSet<unsigned> InstRWProcIndices;
142 
143   CodeGenSchedClass(unsigned Index, std::string Name, Record *ItinClassDef)
144     : Index(Index), Name(std::move(Name)), ItinClassDef(ItinClassDef) {}
145 
146   bool isKeyEqual(Record *IC, ArrayRef<unsigned> W,
147                   ArrayRef<unsigned> R) const {
148     return ItinClassDef == IC && ArrayRef(Writes) == W && ArrayRef(Reads) == R;
149   }
150 
151   // Is this class generated from a variants if existing classes? Instructions
152   // are never mapped directly to inferred scheduling classes.
153   bool isInferred() const { return !ItinClassDef; }
154 
155 #ifndef NDEBUG
156   void dump(const CodeGenSchedModels *SchedModels) const;
157 #endif
158 };
159 
160 /// Represent the cost of allocating a register of register class RCDef.
161 ///
162 /// The cost of allocating a register is equivalent to the number of physical
163 /// registers used by the register renamer. Register costs are defined at
164 /// register class granularity.
165 struct CodeGenRegisterCost {
166   Record *RCDef;
167   unsigned Cost;
168   bool AllowMoveElimination;
169   CodeGenRegisterCost(Record *RC, unsigned RegisterCost, bool AllowMoveElim = false)
170       : RCDef(RC), Cost(RegisterCost), AllowMoveElimination(AllowMoveElim) {}
171   CodeGenRegisterCost(const CodeGenRegisterCost &) = default;
172   CodeGenRegisterCost &operator=(const CodeGenRegisterCost &) = delete;
173 };
174 
175 /// A processor register file.
176 ///
177 /// This class describes a processor register file. Register file information is
178 /// currently consumed by external tools like llvm-mca to predict dispatch
179 /// stalls due to register pressure.
180 struct CodeGenRegisterFile {
181   std::string Name;
182   Record *RegisterFileDef;
183   unsigned MaxMovesEliminatedPerCycle;
184   bool AllowZeroMoveEliminationOnly;
185 
186   unsigned NumPhysRegs;
187   std::vector<CodeGenRegisterCost> Costs;
188 
189   CodeGenRegisterFile(StringRef name, Record *def, unsigned MaxMoveElimPerCy = 0,
190                       bool AllowZeroMoveElimOnly = false)
191       : Name(name), RegisterFileDef(def),
192         MaxMovesEliminatedPerCycle(MaxMoveElimPerCy),
193         AllowZeroMoveEliminationOnly(AllowZeroMoveElimOnly),
194         NumPhysRegs(0) {}
195 
196   bool hasDefaultCosts() const { return Costs.empty(); }
197 };
198 
199 // Processor model.
200 //
201 // ModelName is a unique name used to name an instantiation of MCSchedModel.
202 //
203 // ModelDef is NULL for inferred Models. This happens when a processor defines
204 // an itinerary but no machine model. If the processor defines neither a machine
205 // model nor itinerary, then ModelDef remains pointing to NoModel. NoModel has
206 // the special "NoModel" field set to true.
207 //
208 // ItinsDef always points to a valid record definition, but may point to the
209 // default NoItineraries. NoItineraries has an empty list of InstrItinData
210 // records.
211 //
212 // ItinDefList orders this processor's InstrItinData records by SchedClass idx.
213 struct CodeGenProcModel {
214   unsigned Index;
215   std::string ModelName;
216   Record *ModelDef;
217   Record *ItinsDef;
218 
219   // Derived members...
220 
221   // Array of InstrItinData records indexed by a CodeGenSchedClass index.
222   // This list is empty if the Processor has no value for Itineraries.
223   // Initialized by collectProcItins().
224   RecVec ItinDefList;
225 
226   // Map itinerary classes to per-operand resources.
227   // This list is empty if no ItinRW refers to this Processor.
228   RecVec ItinRWDefs;
229 
230   // List of unsupported feature.
231   // This list is empty if the Processor has no UnsupportedFeatures.
232   RecVec UnsupportedFeaturesDefs;
233 
234   // All read/write resources associated with this processor.
235   RecVec WriteResDefs;
236   RecVec ReadAdvanceDefs;
237 
238   // Per-operand machine model resources associated with this processor.
239   RecVec ProcResourceDefs;
240 
241   // List of Register Files.
242   std::vector<CodeGenRegisterFile> RegisterFiles;
243 
244   // Optional Retire Control Unit definition.
245   Record *RetireControlUnit;
246 
247   // Load/Store queue descriptors.
248   Record *LoadQueue;
249   Record *StoreQueue;
250 
251   CodeGenProcModel(unsigned Idx, std::string Name, Record *MDef,
252                    Record *IDef) :
253     Index(Idx), ModelName(std::move(Name)), ModelDef(MDef), ItinsDef(IDef),
254     RetireControlUnit(nullptr), LoadQueue(nullptr), StoreQueue(nullptr) {}
255 
256   bool hasItineraries() const {
257     return !ItinsDef->getValueAsListOfDefs("IID").empty();
258   }
259 
260   bool hasInstrSchedModel() const {
261     return !WriteResDefs.empty() || !ItinRWDefs.empty();
262   }
263 
264   bool hasExtraProcessorInfo() const {
265     return RetireControlUnit || LoadQueue || StoreQueue ||
266            !RegisterFiles.empty();
267   }
268 
269   unsigned getProcResourceIdx(Record *PRDef) const;
270 
271   bool isUnsupported(const CodeGenInstruction &Inst) const;
272 
273 #ifndef NDEBUG
274   void dump() const;
275 #endif
276 };
277 
278 /// Used to correlate instructions to MCInstPredicates specified by
279 /// InstructionEquivalentClass tablegen definitions.
280 ///
281 /// Example: a XOR of a register with self, is a known zero-idiom for most
282 /// X86 processors.
283 ///
284 /// Each processor can use a (potentially different) InstructionEquivalenceClass
285 ///  definition to classify zero-idioms. That means, XORrr is likely to appear
286 /// in more than one equivalence class (where each class definition is
287 /// contributed by a different processor).
288 ///
289 /// There is no guarantee that the same MCInstPredicate will be used to describe
290 /// equivalence classes that identify XORrr as a zero-idiom.
291 ///
292 /// To be more specific, the requirements for being a zero-idiom XORrr may be
293 /// different for different processors.
294 ///
295 /// Class PredicateInfo identifies a subset of processors that specify the same
296 /// requirements (i.e. same MCInstPredicate and OperandMask) for an instruction
297 /// opcode.
298 ///
299 /// Back to the example. Field `ProcModelMask` will have one bit set for every
300 /// processor model that sees XORrr as a zero-idiom, and that specifies the same
301 /// set of constraints.
302 ///
303 /// By construction, there can be multiple instances of PredicateInfo associated
304 /// with a same instruction opcode. For example, different processors may define
305 /// different constraints on the same opcode.
306 ///
307 /// Field OperandMask can be used as an extra constraint.
308 /// It may be used to describe conditions that appy only to a subset of the
309 /// operands of a machine instruction, and the operands subset may not be the
310 /// same for all processor models.
311 struct PredicateInfo {
312   llvm::APInt ProcModelMask; // A set of processor model indices.
313   llvm::APInt OperandMask;   // An operand mask.
314   const Record *Predicate;   // MCInstrPredicate definition.
315   PredicateInfo(llvm::APInt CpuMask, llvm::APInt Operands, const Record *Pred)
316       : ProcModelMask(CpuMask), OperandMask(Operands), Predicate(Pred) {}
317 
318   bool operator==(const PredicateInfo &Other) const {
319     return ProcModelMask == Other.ProcModelMask &&
320            OperandMask == Other.OperandMask && Predicate == Other.Predicate;
321   }
322 };
323 
324 /// A collection of PredicateInfo objects.
325 ///
326 /// There is at least one OpcodeInfo object for every opcode specified by a
327 /// TIPredicate definition.
328 class OpcodeInfo {
329   std::vector<PredicateInfo> Predicates;
330 
331   OpcodeInfo(const OpcodeInfo &Other) = delete;
332   OpcodeInfo &operator=(const OpcodeInfo &Other) = delete;
333 
334 public:
335   OpcodeInfo() = default;
336   OpcodeInfo &operator=(OpcodeInfo &&Other) = default;
337   OpcodeInfo(OpcodeInfo &&Other) = default;
338 
339   ArrayRef<PredicateInfo> getPredicates() const { return Predicates; }
340 
341   void addPredicateForProcModel(const llvm::APInt &CpuMask,
342                                 const llvm::APInt &OperandMask,
343                                 const Record *Predicate);
344 };
345 
346 /// Used to group together tablegen instruction definitions that are subject
347 /// to a same set of constraints (identified by an instance of OpcodeInfo).
348 class OpcodeGroup {
349   OpcodeInfo Info;
350   std::vector<const Record *> Opcodes;
351 
352   OpcodeGroup(const OpcodeGroup &Other) = delete;
353   OpcodeGroup &operator=(const OpcodeGroup &Other) = delete;
354 
355 public:
356   OpcodeGroup(OpcodeInfo &&OpInfo) : Info(std::move(OpInfo)) {}
357   OpcodeGroup(OpcodeGroup &&Other) = default;
358 
359   void addOpcode(const Record *Opcode) {
360     assert(!llvm::is_contained(Opcodes, Opcode) && "Opcode already in set!");
361     Opcodes.push_back(Opcode);
362   }
363 
364   ArrayRef<const Record *> getOpcodes() const { return Opcodes; }
365   const OpcodeInfo &getOpcodeInfo() const { return Info; }
366 };
367 
368 /// An STIPredicateFunction descriptor used by tablegen backends to
369 /// auto-generate the body of a predicate function as a member of tablegen'd
370 /// class XXXGenSubtargetInfo.
371 class STIPredicateFunction {
372   const Record *FunctionDeclaration;
373 
374   std::vector<const Record *> Definitions;
375   std::vector<OpcodeGroup> Groups;
376 
377   STIPredicateFunction(const STIPredicateFunction &Other) = delete;
378   STIPredicateFunction &operator=(const STIPredicateFunction &Other) = delete;
379 
380 public:
381   STIPredicateFunction(const Record *Rec) : FunctionDeclaration(Rec) {}
382   STIPredicateFunction(STIPredicateFunction &&Other) = default;
383 
384   bool isCompatibleWith(const STIPredicateFunction &Other) const {
385     return FunctionDeclaration == Other.FunctionDeclaration;
386   }
387 
388   void addDefinition(const Record *Def) { Definitions.push_back(Def); }
389   void addOpcode(const Record *OpcodeRec, OpcodeInfo &&Info) {
390     if (Groups.empty() ||
391         Groups.back().getOpcodeInfo().getPredicates() != Info.getPredicates())
392       Groups.emplace_back(std::move(Info));
393     Groups.back().addOpcode(OpcodeRec);
394   }
395 
396   StringRef getName() const {
397     return FunctionDeclaration->getValueAsString("Name");
398   }
399   const Record *getDefaultReturnPredicate() const {
400     return FunctionDeclaration->getValueAsDef("DefaultReturnValue");
401   }
402 
403   const Record *getDeclaration() const { return FunctionDeclaration; }
404   ArrayRef<const Record *> getDefinitions() const { return Definitions; }
405   ArrayRef<OpcodeGroup> getGroups() const { return Groups; }
406 };
407 
408 using ProcModelMapTy = DenseMap<const Record *, unsigned>;
409 
410 /// Top level container for machine model data.
411 class CodeGenSchedModels {
412   RecordKeeper &Records;
413   const CodeGenTarget &Target;
414 
415   // Map dag expressions to Instruction lists.
416   SetTheory Sets;
417 
418   // List of unique processor models.
419   std::vector<CodeGenProcModel> ProcModels;
420 
421   // Map Processor's MachineModel or ProcItin to a CodeGenProcModel index.
422   ProcModelMapTy ProcModelMap;
423 
424   // Per-operand SchedReadWrite types.
425   std::vector<CodeGenSchedRW> SchedWrites;
426   std::vector<CodeGenSchedRW> SchedReads;
427 
428   // List of unique SchedClasses.
429   std::vector<CodeGenSchedClass> SchedClasses;
430 
431   // Any inferred SchedClass has an index greater than NumInstrSchedClassses.
432   unsigned NumInstrSchedClasses;
433 
434   RecVec ProcResourceDefs;
435   RecVec ProcResGroups;
436 
437   // Map each instruction to its unique SchedClass index considering the
438   // combination of it's itinerary class, SchedRW list, and InstRW records.
439   using InstClassMapTy = DenseMap<Record*, unsigned>;
440   InstClassMapTy InstrClassMap;
441 
442   std::vector<STIPredicateFunction> STIPredicates;
443   std::vector<unsigned> getAllProcIndices() const;
444 
445 public:
446   CodeGenSchedModels(RecordKeeper& RK, const CodeGenTarget &TGT);
447 
448   // iterator access to the scheduling classes.
449   using class_iterator = std::vector<CodeGenSchedClass>::iterator;
450   using const_class_iterator = std::vector<CodeGenSchedClass>::const_iterator;
451   class_iterator classes_begin() { return SchedClasses.begin(); }
452   const_class_iterator classes_begin() const { return SchedClasses.begin(); }
453   class_iterator classes_end() { return SchedClasses.end(); }
454   const_class_iterator classes_end() const { return SchedClasses.end(); }
455   iterator_range<class_iterator> classes() {
456    return make_range(classes_begin(), classes_end());
457   }
458   iterator_range<const_class_iterator> classes() const {
459    return make_range(classes_begin(), classes_end());
460   }
461   iterator_range<class_iterator> explicit_classes() {
462     return make_range(classes_begin(), classes_begin() + NumInstrSchedClasses);
463   }
464   iterator_range<const_class_iterator> explicit_classes() const {
465     return make_range(classes_begin(), classes_begin() + NumInstrSchedClasses);
466   }
467 
468   Record *getModelOrItinDef(Record *ProcDef) const {
469     Record *ModelDef = ProcDef->getValueAsDef("SchedModel");
470     Record *ItinsDef = ProcDef->getValueAsDef("ProcItin");
471     if (!ItinsDef->getValueAsListOfDefs("IID").empty()) {
472       assert(ModelDef->getValueAsBit("NoModel")
473              && "Itineraries must be defined within SchedMachineModel");
474       return ItinsDef;
475     }
476     return ModelDef;
477   }
478 
479   const CodeGenProcModel &getModelForProc(Record *ProcDef) const {
480     Record *ModelDef = getModelOrItinDef(ProcDef);
481     ProcModelMapTy::const_iterator I = ProcModelMap.find(ModelDef);
482     assert(I != ProcModelMap.end() && "missing machine model");
483     return ProcModels[I->second];
484   }
485 
486   CodeGenProcModel &getProcModel(Record *ModelDef) {
487     ProcModelMapTy::const_iterator I = ProcModelMap.find(ModelDef);
488     assert(I != ProcModelMap.end() && "missing machine model");
489     return ProcModels[I->second];
490   }
491   const CodeGenProcModel &getProcModel(Record *ModelDef) const {
492     return const_cast<CodeGenSchedModels*>(this)->getProcModel(ModelDef);
493   }
494 
495   // Iterate over the unique processor models.
496   using ProcIter = std::vector<CodeGenProcModel>::const_iterator;
497   ProcIter procModelBegin() const { return ProcModels.begin(); }
498   ProcIter procModelEnd() const { return ProcModels.end(); }
499   ArrayRef<CodeGenProcModel> procModels() const { return ProcModels; }
500 
501   // Return true if any processors have itineraries.
502   bool hasItineraries() const;
503 
504   // Get a SchedWrite from its index.
505   const CodeGenSchedRW &getSchedWrite(unsigned Idx) const {
506     assert(Idx < SchedWrites.size() && "bad SchedWrite index");
507     assert(SchedWrites[Idx].isValid() && "invalid SchedWrite");
508     return SchedWrites[Idx];
509   }
510   // Get a SchedWrite from its index.
511   const CodeGenSchedRW &getSchedRead(unsigned Idx) const {
512     assert(Idx < SchedReads.size() && "bad SchedRead index");
513     assert(SchedReads[Idx].isValid() && "invalid SchedRead");
514     return SchedReads[Idx];
515   }
516 
517   const CodeGenSchedRW &getSchedRW(unsigned Idx, bool IsRead) const {
518     return IsRead ? getSchedRead(Idx) : getSchedWrite(Idx);
519   }
520   CodeGenSchedRW &getSchedRW(Record *Def) {
521     bool IsRead = Def->isSubClassOf("SchedRead");
522     unsigned Idx = getSchedRWIdx(Def, IsRead);
523     return const_cast<CodeGenSchedRW&>(
524       IsRead ? getSchedRead(Idx) : getSchedWrite(Idx));
525   }
526   const CodeGenSchedRW &getSchedRW(Record *Def) const {
527     return const_cast<CodeGenSchedModels&>(*this).getSchedRW(Def);
528   }
529 
530   unsigned getSchedRWIdx(const Record *Def, bool IsRead) const;
531 
532   // Return true if the given write record is referenced by a ReadAdvance.
533   bool hasReadOfWrite(Record *WriteDef) const;
534 
535   // Get a SchedClass from its index.
536   CodeGenSchedClass &getSchedClass(unsigned Idx) {
537     assert(Idx < SchedClasses.size() && "bad SchedClass index");
538     return SchedClasses[Idx];
539   }
540   const CodeGenSchedClass &getSchedClass(unsigned Idx) const {
541     assert(Idx < SchedClasses.size() && "bad SchedClass index");
542     return SchedClasses[Idx];
543   }
544 
545   // Get the SchedClass index for an instruction. Instructions with no
546   // itinerary, no SchedReadWrites, and no InstrReadWrites references return 0
547   // for NoItinerary.
548   unsigned getSchedClassIdx(const CodeGenInstruction &Inst) const;
549 
550   using SchedClassIter = std::vector<CodeGenSchedClass>::const_iterator;
551   SchedClassIter schedClassBegin() const { return SchedClasses.begin(); }
552   SchedClassIter schedClassEnd() const { return SchedClasses.end(); }
553   ArrayRef<CodeGenSchedClass> schedClasses() const { return SchedClasses; }
554 
555   unsigned numInstrSchedClasses() const { return NumInstrSchedClasses; }
556 
557   void findRWs(const RecVec &RWDefs, IdxVec &Writes, IdxVec &Reads) const;
558   void findRWs(const RecVec &RWDefs, IdxVec &RWs, bool IsRead) const;
559   void expandRWSequence(unsigned RWIdx, IdxVec &RWSeq, bool IsRead) const;
560   void expandRWSeqForProc(unsigned RWIdx, IdxVec &RWSeq, bool IsRead,
561                           const CodeGenProcModel &ProcModel) const;
562 
563   unsigned addSchedClass(Record *ItinDef, ArrayRef<unsigned> OperWrites,
564                          ArrayRef<unsigned> OperReads,
565                          ArrayRef<unsigned> ProcIndices);
566 
567   unsigned findOrInsertRW(ArrayRef<unsigned> Seq, bool IsRead);
568 
569   Record *findProcResUnits(Record *ProcResKind, const CodeGenProcModel &PM,
570                            ArrayRef<SMLoc> Loc) const;
571 
572   ArrayRef<STIPredicateFunction> getSTIPredicates() const {
573     return STIPredicates;
574   }
575 private:
576   void collectProcModels();
577 
578   // Initialize a new processor model if it is unique.
579   void addProcModel(Record *ProcDef);
580 
581   void collectSchedRW();
582 
583   std::string genRWName(ArrayRef<unsigned> Seq, bool IsRead);
584   unsigned findRWForSequence(ArrayRef<unsigned> Seq, bool IsRead);
585 
586   void collectSchedClasses();
587 
588   void collectRetireControlUnits();
589 
590   void collectRegisterFiles();
591 
592   void collectOptionalProcessorInfo();
593 
594   std::string createSchedClassName(Record *ItinClassDef,
595                                    ArrayRef<unsigned> OperWrites,
596                                    ArrayRef<unsigned> OperReads);
597   std::string createSchedClassName(const RecVec &InstDefs);
598   void createInstRWClass(Record *InstRWDef);
599 
600   void collectProcItins();
601 
602   void collectProcItinRW();
603 
604   void collectProcUnsupportedFeatures();
605 
606   void inferSchedClasses();
607 
608   void checkMCInstPredicates() const;
609 
610   void checkSTIPredicates() const;
611 
612   void collectSTIPredicates();
613 
614   void collectLoadStoreQueueInfo();
615 
616   void checkCompleteness();
617 
618   void inferFromRW(ArrayRef<unsigned> OperWrites, ArrayRef<unsigned> OperReads,
619                    unsigned FromClassIdx, ArrayRef<unsigned> ProcIndices);
620   void inferFromItinClass(Record *ItinClassDef, unsigned FromClassIdx);
621   void inferFromInstRWs(unsigned SCIdx);
622 
623   bool hasSuperGroup(RecVec &SubUnits, CodeGenProcModel &PM);
624   void verifyProcResourceGroups(CodeGenProcModel &PM);
625 
626   void collectProcResources();
627 
628   void collectItinProcResources(Record *ItinClassDef);
629 
630   void collectRWResources(unsigned RWIdx, bool IsRead,
631                           ArrayRef<unsigned> ProcIndices);
632 
633   void collectRWResources(ArrayRef<unsigned> Writes, ArrayRef<unsigned> Reads,
634                           ArrayRef<unsigned> ProcIndices);
635 
636   void addProcResource(Record *ProcResourceKind, CodeGenProcModel &PM,
637                        ArrayRef<SMLoc> Loc);
638 
639   void addWriteRes(Record *ProcWriteResDef, unsigned PIdx);
640 
641   void addReadAdvance(Record *ProcReadAdvanceDef, unsigned PIdx);
642 };
643 
644 } // namespace llvm
645 
646 #endif
647