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