ba62db48274c6baae9493fc36a0fd236aaa564e1
[oota-llvm.git] / utils / TableGen / CodeGenRegisters.h
1 //===- CodeGenRegisters.h - Register and RegisterClass Info -----*- C++ -*-===//
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 //
10 // This file defines structures to encapsulate information gleaned from the
11 // target register and register class definitions.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef CODEGEN_REGISTERS_H
16 #define CODEGEN_REGISTERS_H
17
18 #include "SetTheory.h"
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/BitVector.h"
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/ADT/SetVector.h"
23 #include "llvm/CodeGen/ValueTypes.h"
24 #include "llvm/Support/ErrorHandling.h"
25 #include "llvm/TableGen/Record.h"
26 #include <cstdlib>
27 #include <map>
28 #include <set>
29 #include <string>
30 #include <vector>
31
32 namespace llvm {
33   class CodeGenRegBank;
34
35   /// CodeGenSubRegIndex - Represents a sub-register index.
36   class CodeGenSubRegIndex {
37     Record *const TheDef;
38     std::string Name;
39     std::string Namespace;
40
41   public:
42     const unsigned EnumValue;
43     unsigned LaneMask;
44
45     // Are all super-registers containing this SubRegIndex covered by their
46     // sub-registers?
47     bool AllSuperRegsCovered;
48
49     CodeGenSubRegIndex(Record *R, unsigned Enum);
50     CodeGenSubRegIndex(StringRef N, StringRef Nspace, unsigned Enum);
51
52     const std::string &getName() const { return Name; }
53     const std::string &getNamespace() const { return Namespace; }
54     std::string getQualifiedName() const;
55
56     // Order CodeGenSubRegIndex pointers by EnumValue.
57     struct Less {
58       bool operator()(const CodeGenSubRegIndex *A,
59                       const CodeGenSubRegIndex *B) const {
60         assert(A && B);
61         return A->EnumValue < B->EnumValue;
62       }
63     };
64
65     // Map of composite subreg indices.
66     typedef std::map<CodeGenSubRegIndex*, CodeGenSubRegIndex*, Less> CompMap;
67
68     // Returns the subreg index that results from composing this with Idx.
69     // Returns NULL if this and Idx don't compose.
70     CodeGenSubRegIndex *compose(CodeGenSubRegIndex *Idx) const {
71       CompMap::const_iterator I = Composed.find(Idx);
72       return I == Composed.end() ? 0 : I->second;
73     }
74
75     // Add a composite subreg index: this+A = B.
76     // Return a conflicting composite, or NULL
77     CodeGenSubRegIndex *addComposite(CodeGenSubRegIndex *A,
78                                      CodeGenSubRegIndex *B) {
79       assert(A && B);
80       std::pair<CompMap::iterator, bool> Ins =
81         Composed.insert(std::make_pair(A, B));
82       return (Ins.second || Ins.first->second == B) ? 0 : Ins.first->second;
83     }
84
85     // Update the composite maps of components specified in 'ComposedOf'.
86     void updateComponents(CodeGenRegBank&);
87
88     // Return the map of composites.
89     const CompMap &getComposites() const { return Composed; }
90
91     // Compute LaneMask from Composed. Return LaneMask.
92     unsigned computeLaneMask();
93
94   private:
95     CompMap Composed;
96   };
97
98   /// CodeGenRegister - Represents a register definition.
99   struct CodeGenRegister {
100     Record *TheDef;
101     unsigned EnumValue;
102     unsigned CostPerUse;
103     bool CoveredBySubRegs;
104
105     // Map SubRegIndex -> Register.
106     typedef std::map<CodeGenSubRegIndex*, CodeGenRegister*,
107                      CodeGenSubRegIndex::Less> SubRegMap;
108
109     CodeGenRegister(Record *R, unsigned Enum);
110
111     const std::string &getName() const;
112
113     // Extract more information from TheDef. This is used to build an object
114     // graph after all CodeGenRegister objects have been created.
115     void buildObjectGraph(CodeGenRegBank&);
116
117     // Lazily compute a map of all sub-registers.
118     // This includes unique entries for all sub-sub-registers.
119     const SubRegMap &computeSubRegs(CodeGenRegBank&);
120
121     // Compute extra sub-registers by combining the existing sub-registers.
122     void computeSecondarySubRegs(CodeGenRegBank&);
123
124     // Add this as a super-register to all sub-registers after the sub-register
125     // graph has been built.
126     void computeSuperRegs(CodeGenRegBank&);
127
128     const SubRegMap &getSubRegs() const {
129       assert(SubRegsComplete && "Must precompute sub-registers");
130       return SubRegs;
131     }
132
133     // Add sub-registers to OSet following a pre-order defined by the .td file.
134     void addSubRegsPreOrder(SetVector<const CodeGenRegister*> &OSet,
135                             CodeGenRegBank&) const;
136
137     // Return the sub-register index naming Reg as a sub-register of this
138     // register. Returns NULL if Reg is not a sub-register.
139     CodeGenSubRegIndex *getSubRegIndex(const CodeGenRegister *Reg) const {
140       return SubReg2Idx.lookup(Reg);
141     }
142
143     typedef std::vector<const CodeGenRegister*> SuperRegList;
144
145     // Get the list of super-registers in topological order, small to large.
146     // This is valid after computeSubRegs visits all registers during RegBank
147     // construction.
148     const SuperRegList &getSuperRegs() const {
149       assert(SubRegsComplete && "Must precompute sub-registers");
150       return SuperRegs;
151     }
152
153     // Get the list of ad hoc aliases. The graph is symmetric, so the list
154     // contains all registers in 'Aliases', and all registers that mention this
155     // register in 'Aliases'.
156     ArrayRef<CodeGenRegister*> getExplicitAliases() const {
157       return ExplicitAliases;
158     }
159
160     // Get the topological signature of this register. This is a small integer
161     // less than RegBank.getNumTopoSigs(). Registers with the same TopoSig have
162     // identical sub-register structure. That is, they support the same set of
163     // sub-register indices mapping to the same kind of sub-registers
164     // (TopoSig-wise).
165     unsigned getTopoSig() const {
166       assert(SuperRegsComplete && "TopoSigs haven't been computed yet.");
167       return TopoSig;
168     }
169
170     // List of register units in ascending order.
171     typedef SmallVector<unsigned, 16> RegUnitList;
172
173     // How many entries in RegUnitList are native?
174     unsigned NumNativeRegUnits;
175
176     // Get the list of register units.
177     // This is only valid after computeSubRegs() completes.
178     const RegUnitList &getRegUnits() const { return RegUnits; }
179
180     // Get the native register units. This is a prefix of getRegUnits().
181     ArrayRef<unsigned> getNativeRegUnits() const {
182       return makeArrayRef(RegUnits).slice(0, NumNativeRegUnits);
183     }
184
185     // Inherit register units from subregisters.
186     // Return true if the RegUnits changed.
187     bool inheritRegUnits(CodeGenRegBank &RegBank);
188
189     // Adopt a register unit for pressure tracking.
190     // A unit is adopted iff its unit number is >= NumNativeRegUnits.
191     void adoptRegUnit(unsigned RUID) { RegUnits.push_back(RUID); }
192
193     // Get the sum of this register's register unit weights.
194     unsigned getWeight(const CodeGenRegBank &RegBank) const;
195
196     // Order CodeGenRegister pointers by EnumValue.
197     struct Less {
198       bool operator()(const CodeGenRegister *A,
199                       const CodeGenRegister *B) const {
200         assert(A && B);
201         return A->EnumValue < B->EnumValue;
202       }
203     };
204
205     // Canonically ordered set.
206     typedef std::set<const CodeGenRegister*, Less> Set;
207
208   private:
209     bool SubRegsComplete;
210     bool SuperRegsComplete;
211     unsigned TopoSig;
212
213     // The sub-registers explicit in the .td file form a tree.
214     SmallVector<CodeGenSubRegIndex*, 8> ExplicitSubRegIndices;
215     SmallVector<CodeGenRegister*, 8> ExplicitSubRegs;
216
217     // Explicit ad hoc aliases, symmetrized to form an undirected graph.
218     SmallVector<CodeGenRegister*, 8> ExplicitAliases;
219
220     // Super-registers where this is the first explicit sub-register.
221     SuperRegList LeadingSuperRegs;
222
223     SubRegMap SubRegs;
224     SuperRegList SuperRegs;
225     DenseMap<const CodeGenRegister*, CodeGenSubRegIndex*> SubReg2Idx;
226     RegUnitList RegUnits;
227   };
228
229
230   class CodeGenRegisterClass {
231     CodeGenRegister::Set Members;
232     // Allocation orders. Order[0] always contains all registers in Members.
233     std::vector<SmallVector<Record*, 16> > Orders;
234     // Bit mask of sub-classes including this, indexed by their EnumValue.
235     BitVector SubClasses;
236     // List of super-classes, topologocally ordered to have the larger classes
237     // first.  This is the same as sorting by EnumValue.
238     SmallVector<CodeGenRegisterClass*, 4> SuperClasses;
239     Record *TheDef;
240     std::string Name;
241
242     // For a synthesized class, inherit missing properties from the nearest
243     // super-class.
244     void inheritProperties(CodeGenRegBank&);
245
246     // Map SubRegIndex -> sub-class.  This is the largest sub-class where all
247     // registers have a SubRegIndex sub-register.
248     DenseMap<CodeGenSubRegIndex*, CodeGenRegisterClass*> SubClassWithSubReg;
249
250     // Map SubRegIndex -> set of super-reg classes.  This is all register
251     // classes SuperRC such that:
252     //
253     //   R:SubRegIndex in this RC for all R in SuperRC.
254     //
255     DenseMap<CodeGenSubRegIndex*,
256              SmallPtrSet<CodeGenRegisterClass*, 8> > SuperRegClasses;
257
258     // Bit vector of TopoSigs for the registers in this class. This will be
259     // very sparse on regular architectures.
260     BitVector TopoSigs;
261
262   public:
263     unsigned EnumValue;
264     std::string Namespace;
265     SmallVector<MVT::SimpleValueType, 4> VTs;
266     unsigned SpillSize;
267     unsigned SpillAlignment;
268     int CopyCost;
269     bool Allocatable;
270     std::string AltOrderSelect;
271
272     // Return the Record that defined this class, or NULL if the class was
273     // created by TableGen.
274     Record *getDef() const { return TheDef; }
275
276     const std::string &getName() const { return Name; }
277     std::string getQualifiedName() const;
278     ArrayRef<MVT::SimpleValueType> getValueTypes() const {return VTs;}
279     unsigned getNumValueTypes() const { return VTs.size(); }
280
281     MVT::SimpleValueType getValueTypeNum(unsigned VTNum) const {
282       if (VTNum < VTs.size())
283         return VTs[VTNum];
284       llvm_unreachable("VTNum greater than number of ValueTypes in RegClass!");
285     }
286
287     // Return true if this this class contains the register.
288     bool contains(const CodeGenRegister*) const;
289
290     // Returns true if RC is a subclass.
291     // RC is a sub-class of this class if it is a valid replacement for any
292     // instruction operand where a register of this classis required. It must
293     // satisfy these conditions:
294     //
295     // 1. All RC registers are also in this.
296     // 2. The RC spill size must not be smaller than our spill size.
297     // 3. RC spill alignment must be compatible with ours.
298     //
299     bool hasSubClass(const CodeGenRegisterClass *RC) const {
300       return SubClasses.test(RC->EnumValue);
301     }
302
303     // getSubClassWithSubReg - Returns the largest sub-class where all
304     // registers have a SubIdx sub-register.
305     CodeGenRegisterClass*
306     getSubClassWithSubReg(CodeGenSubRegIndex *SubIdx) const {
307       return SubClassWithSubReg.lookup(SubIdx);
308     }
309
310     void setSubClassWithSubReg(CodeGenSubRegIndex *SubIdx,
311                                CodeGenRegisterClass *SubRC) {
312       SubClassWithSubReg[SubIdx] = SubRC;
313     }
314
315     // getSuperRegClasses - Returns a bit vector of all register classes
316     // containing only SubIdx super-registers of this class.
317     void getSuperRegClasses(CodeGenSubRegIndex *SubIdx, BitVector &Out) const;
318
319     // addSuperRegClass - Add a class containing only SudIdx super-registers.
320     void addSuperRegClass(CodeGenSubRegIndex *SubIdx,
321                           CodeGenRegisterClass *SuperRC) {
322       SuperRegClasses[SubIdx].insert(SuperRC);
323     }
324
325     // getSubClasses - Returns a constant BitVector of subclasses indexed by
326     // EnumValue.
327     // The SubClasses vector includs an entry for this class.
328     const BitVector &getSubClasses() const { return SubClasses; }
329
330     // getSuperClasses - Returns a list of super classes ordered by EnumValue.
331     // The array does not include an entry for this class.
332     ArrayRef<CodeGenRegisterClass*> getSuperClasses() const {
333       return SuperClasses;
334     }
335
336     // Returns an ordered list of class members.
337     // The order of registers is the same as in the .td file.
338     // No = 0 is the default allocation order, No = 1 is the first alternative.
339     ArrayRef<Record*> getOrder(unsigned No = 0) const {
340         return Orders[No];
341     }
342
343     // Return the total number of allocation orders available.
344     unsigned getNumOrders() const { return Orders.size(); }
345
346     // Get the set of registers.  This set contains the same registers as
347     // getOrder(0).
348     const CodeGenRegister::Set &getMembers() const { return Members; }
349
350     // Get a bit vector of TopoSigs present in this register class.
351     const BitVector &getTopoSigs() const { return TopoSigs; }
352
353     // Populate a unique sorted list of units from a register set.
354     void buildRegUnitSet(std::vector<unsigned> &RegUnits) const;
355
356     CodeGenRegisterClass(CodeGenRegBank&, Record *R);
357
358     // A key representing the parts of a register class used for forming
359     // sub-classes.  Note the ordering provided by this key is not the same as
360     // the topological order used for the EnumValues.
361     struct Key {
362       const CodeGenRegister::Set *Members;
363       unsigned SpillSize;
364       unsigned SpillAlignment;
365
366       Key(const Key &O)
367         : Members(O.Members),
368           SpillSize(O.SpillSize),
369           SpillAlignment(O.SpillAlignment) {}
370
371       Key(const CodeGenRegister::Set *M, unsigned S = 0, unsigned A = 0)
372         : Members(M), SpillSize(S), SpillAlignment(A) {}
373
374       Key(const CodeGenRegisterClass &RC)
375         : Members(&RC.getMembers()),
376           SpillSize(RC.SpillSize),
377           SpillAlignment(RC.SpillAlignment) {}
378
379       // Lexicographical order of (Members, SpillSize, SpillAlignment).
380       bool operator<(const Key&) const;
381     };
382
383     // Create a non-user defined register class.
384     CodeGenRegisterClass(CodeGenRegBank&, StringRef Name, Key Props);
385
386     // Called by CodeGenRegBank::CodeGenRegBank().
387     static void computeSubClasses(CodeGenRegBank&);
388   };
389
390   // Register units are used to model interference and register pressure.
391   // Every register is assigned one or more register units such that two
392   // registers overlap if and only if they have a register unit in common.
393   //
394   // Normally, one register unit is created per leaf register. Non-leaf
395   // registers inherit the units of their sub-registers.
396   struct RegUnit {
397     // Weight assigned to this RegUnit for estimating register pressure.
398     // This is useful when equalizing weights in register classes with mixed
399     // register topologies.
400     unsigned Weight;
401
402     // Each native RegUnit corresponds to one or two root registers. The full
403     // set of registers containing this unit can be computed as the union of
404     // these two registers and their super-registers.
405     const CodeGenRegister *Roots[2];
406
407     // Index into RegClassUnitSets where we can find the list of UnitSets that
408     // contain this unit.
409     unsigned RegClassUnitSetsIdx;
410
411     RegUnit() : Weight(0), RegClassUnitSetsIdx(0) { Roots[0] = Roots[1] = 0; }
412
413     ArrayRef<const CodeGenRegister*> getRoots() const {
414       assert(!(Roots[1] && !Roots[0]) && "Invalid roots array");
415       return makeArrayRef(Roots, !!Roots[0] + !!Roots[1]);
416     }
417   };
418
419   // Each RegUnitSet is a sorted vector with a name.
420   struct RegUnitSet {
421     typedef std::vector<unsigned>::const_iterator iterator;
422
423     std::string Name;
424     std::vector<unsigned> Units;
425   };
426
427   // Base vector for identifying TopoSigs. The contents uniquely identify a
428   // TopoSig, only computeSuperRegs needs to know how.
429   typedef SmallVector<unsigned, 16> TopoSigId;
430
431   // CodeGenRegBank - Represent a target's registers and the relations between
432   // them.
433   class CodeGenRegBank {
434     SetTheory Sets;
435
436     // SubRegIndices.
437     std::vector<CodeGenSubRegIndex*> SubRegIndices;
438     DenseMap<Record*, CodeGenSubRegIndex*> Def2SubRegIdx;
439
440     CodeGenSubRegIndex *createSubRegIndex(StringRef Name, StringRef NameSpace);
441
442     typedef std::map<SmallVector<CodeGenSubRegIndex*, 8>,
443                      CodeGenSubRegIndex*> ConcatIdxMap;
444     ConcatIdxMap ConcatIdx;
445
446     // Registers.
447     std::vector<CodeGenRegister*> Registers;
448     StringMap<CodeGenRegister*> RegistersByName;
449     DenseMap<Record*, CodeGenRegister*> Def2Reg;
450     unsigned NumNativeRegUnits;
451
452     std::map<TopoSigId, unsigned> TopoSigs;
453
454     // Includes native (0..NumNativeRegUnits-1) and adopted register units.
455     SmallVector<RegUnit, 8> RegUnits;
456
457     // Register classes.
458     std::vector<CodeGenRegisterClass*> RegClasses;
459     DenseMap<Record*, CodeGenRegisterClass*> Def2RC;
460     typedef std::map<CodeGenRegisterClass::Key, CodeGenRegisterClass*> RCKeyMap;
461     RCKeyMap Key2RC;
462
463     // Remember each unique set of register units. Initially, this contains a
464     // unique set for each register class. Simliar sets are coalesced with
465     // pruneUnitSets and new supersets are inferred during computeRegUnitSets.
466     std::vector<RegUnitSet> RegUnitSets;
467
468     // Map RegisterClass index to the index of the RegUnitSet that contains the
469     // class's units and any inferred RegUnit supersets.
470     //
471     // NOTE: This could grow beyond the number of register classes when we map
472     // register units to lists of unit sets. If the list of unit sets does not
473     // already exist for a register class, we create a new entry in this vector.
474     std::vector<std::vector<unsigned> > RegClassUnitSets;
475
476     // Add RC to *2RC maps.
477     void addToMaps(CodeGenRegisterClass*);
478
479     // Create a synthetic sub-class if it is missing.
480     CodeGenRegisterClass *getOrCreateSubClass(const CodeGenRegisterClass *RC,
481                                               const CodeGenRegister::Set *Membs,
482                                               StringRef Name);
483
484     // Infer missing register classes.
485     void computeInferredRegisterClasses();
486     void inferCommonSubClass(CodeGenRegisterClass *RC);
487     void inferSubClassWithSubReg(CodeGenRegisterClass *RC);
488     void inferMatchingSuperRegClass(CodeGenRegisterClass *RC,
489                                     unsigned FirstSubRegRC = 0);
490
491     // Iteratively prune unit sets.
492     void pruneUnitSets();
493
494     // Compute a weight for each register unit created during getSubRegs.
495     void computeRegUnitWeights();
496
497     // Create a RegUnitSet for each RegClass and infer superclasses.
498     void computeRegUnitSets();
499
500     // Populate the Composite map from sub-register relationships.
501     void computeComposites();
502
503     // Compute a lane mask for each sub-register index.
504     void computeSubRegIndexLaneMasks();
505
506   public:
507     CodeGenRegBank(RecordKeeper&);
508
509     SetTheory &getSets() { return Sets; }
510
511     // Sub-register indices. The first NumNamedIndices are defined by the user
512     // in the .td files. The rest are synthesized such that all sub-registers
513     // have a unique name.
514     ArrayRef<CodeGenSubRegIndex*> getSubRegIndices() { return SubRegIndices; }
515
516     // Find a SubRegIndex form its Record def.
517     CodeGenSubRegIndex *getSubRegIdx(Record*);
518
519     // Find or create a sub-register index representing the A+B composition.
520     CodeGenSubRegIndex *getCompositeSubRegIndex(CodeGenSubRegIndex *A,
521                                                 CodeGenSubRegIndex *B);
522
523     // Find or create a sub-register index representing the concatenation of
524     // non-overlapping sibling indices.
525     CodeGenSubRegIndex *
526       getConcatSubRegIndex(const SmallVector<CodeGenSubRegIndex*, 8>&);
527
528     void
529     addConcatSubRegIndex(const SmallVector<CodeGenSubRegIndex*, 8> &Parts,
530                          CodeGenSubRegIndex *Idx) {
531       ConcatIdx.insert(std::make_pair(Parts, Idx));
532     }
533
534     const std::vector<CodeGenRegister*> &getRegisters() { return Registers; }
535     const StringMap<CodeGenRegister*> &getRegistersByName() {
536       return RegistersByName;
537     }
538
539     // Find a register from its Record def.
540     CodeGenRegister *getReg(Record*);
541
542     // Get a Register's index into the Registers array.
543     unsigned getRegIndex(const CodeGenRegister *Reg) const {
544       return Reg->EnumValue - 1;
545     }
546
547     // Return the number of allocated TopoSigs. The first TopoSig representing
548     // leaf registers is allocated number 0.
549     unsigned getNumTopoSigs() const {
550       return TopoSigs.size();
551     }
552
553     // Find or create a TopoSig for the given TopoSigId.
554     // This function is only for use by CodeGenRegister::computeSuperRegs().
555     // Others should simply use Reg->getTopoSig().
556     unsigned getTopoSig(const TopoSigId &Id) {
557       return TopoSigs.insert(std::make_pair(Id, TopoSigs.size())).first->second;
558     }
559
560     // Create a native register unit that is associated with one or two root
561     // registers.
562     unsigned newRegUnit(CodeGenRegister *R0, CodeGenRegister *R1 = 0) {
563       RegUnits.resize(RegUnits.size() + 1);
564       RegUnits.back().Roots[0] = R0;
565       RegUnits.back().Roots[1] = R1;
566       return RegUnits.size() - 1;
567     }
568
569     // Create a new non-native register unit that can be adopted by a register
570     // to increase its pressure. Note that NumNativeRegUnits is not increased.
571     unsigned newRegUnit(unsigned Weight) {
572       RegUnits.resize(RegUnits.size() + 1);
573       RegUnits.back().Weight = Weight;
574       return RegUnits.size() - 1;
575     }
576
577     // Native units are the singular unit of a leaf register. Register aliasing
578     // is completely characterized by native units. Adopted units exist to give
579     // register additional weight but don't affect aliasing.
580     bool isNativeUnit(unsigned RUID) {
581       return RUID < NumNativeRegUnits;
582     }
583
584     unsigned getNumNativeRegUnits() const {
585       return NumNativeRegUnits;
586     }
587
588     RegUnit &getRegUnit(unsigned RUID) { return RegUnits[RUID]; }
589     const RegUnit &getRegUnit(unsigned RUID) const { return RegUnits[RUID]; }
590
591     ArrayRef<CodeGenRegisterClass*> getRegClasses() const {
592       return RegClasses;
593     }
594
595     // Find a register class from its def.
596     CodeGenRegisterClass *getRegClass(Record*);
597
598     /// getRegisterClassForRegister - Find the register class that contains the
599     /// specified physical register.  If the register is not in a register
600     /// class, return null. If the register is in multiple classes, and the
601     /// classes have a superset-subset relationship and the same set of types,
602     /// return the superclass.  Otherwise return null.
603     const CodeGenRegisterClass* getRegClassForRegister(Record *R);
604
605     // Get the sum of unit weights.
606     unsigned getRegUnitSetWeight(const std::vector<unsigned> &Units) const {
607       unsigned Weight = 0;
608       for (std::vector<unsigned>::const_iterator
609              I = Units.begin(), E = Units.end(); I != E; ++I)
610         Weight += getRegUnit(*I).Weight;
611       return Weight;
612     }
613
614     // Increase a RegUnitWeight.
615     void increaseRegUnitWeight(unsigned RUID, unsigned Inc) {
616       getRegUnit(RUID).Weight += Inc;
617     }
618
619     // Get the number of register pressure dimensions.
620     unsigned getNumRegPressureSets() const { return RegUnitSets.size(); }
621
622     // Get a set of register unit IDs for a given dimension of pressure.
623     RegUnitSet getRegPressureSet(unsigned Idx) const {
624       return RegUnitSets[Idx];
625     }
626
627     // The number of pressure set lists may be larget than the number of
628     // register classes if some register units appeared in a list of sets that
629     // did not correspond to an existing register class.
630     unsigned getNumRegClassPressureSetLists() const {
631       return RegClassUnitSets.size();
632     }
633
634     // Get a list of pressure set IDs for a register class. Liveness of a
635     // register in this class impacts each pressure set in this list by the
636     // weight of the register. An exact solution requires all registers in a
637     // class to have the same class, but it is not strictly guaranteed.
638     ArrayRef<unsigned> getRCPressureSetIDs(unsigned RCIdx) const {
639       return RegClassUnitSets[RCIdx];
640     }
641
642     // Computed derived records such as missing sub-register indices.
643     void computeDerivedInfo();
644
645     // Compute the set of registers completely covered by the registers in Regs.
646     // The returned BitVector will have a bit set for each register in Regs,
647     // all sub-registers, and all super-registers that are covered by the
648     // registers in Regs.
649     //
650     // This is used to compute the mask of call-preserved registers from a list
651     // of callee-saves.
652     BitVector computeCoveredRegisters(ArrayRef<Record*> Regs);
653
654     // Bit mask of lanes that cover their registers. A sub-register index whose
655     // LaneMask is contained in CoveringLanes will be completely covered by
656     // another sub-register with the same or larger lane mask.
657     unsigned CoveringLanes;
658   };
659 }
660
661 #endif