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