LLVM API Documentation

MCRegisterInfo.h
Go to the documentation of this file.
00001 //=== MC/MCRegisterInfo.h - Target Register Description ---------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file describes an abstract interface used to get information about a
00011 // target machines register file.  This information is used for a variety of
00012 // purposed, especially register allocation.
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #ifndef LLVM_MC_MCREGISTERINFO_H
00017 #define LLVM_MC_MCREGISTERINFO_H
00018 
00019 #include "llvm/ADT/DenseMap.h"
00020 #include "llvm/Support/ErrorHandling.h"
00021 #include <cassert>
00022 
00023 namespace llvm {
00024 
00025 /// An unsigned integer type large enough to represent all physical registers,
00026 /// but not necessarily virtual registers.
00027 typedef uint16_t MCPhysReg;
00028 
00029 /// MCRegisterClass - Base class of TargetRegisterClass.
00030 class MCRegisterClass {
00031 public:
00032   typedef const MCPhysReg* iterator;
00033   typedef const MCPhysReg* const_iterator;
00034 
00035   const char *Name;
00036   const iterator RegsBegin;
00037   const uint8_t *const RegSet;
00038   const uint16_t RegsSize;
00039   const uint16_t RegSetSize;
00040   const uint16_t ID;
00041   const uint16_t RegSize, Alignment; // Size & Alignment of register in bytes
00042   const int8_t CopyCost;
00043   const bool Allocatable;
00044 
00045   /// getID() - Return the register class ID number.
00046   ///
00047   unsigned getID() const { return ID; }
00048 
00049   /// getName() - Return the register class name for debugging.
00050   ///
00051   const char *getName() const { return Name; }
00052 
00053   /// begin/end - Return all of the registers in this class.
00054   ///
00055   iterator       begin() const { return RegsBegin; }
00056   iterator         end() const { return RegsBegin + RegsSize; }
00057 
00058   /// getNumRegs - Return the number of registers in this class.
00059   ///
00060   unsigned getNumRegs() const { return RegsSize; }
00061 
00062   /// getRegister - Return the specified register in the class.
00063   ///
00064   unsigned getRegister(unsigned i) const {
00065     assert(i < getNumRegs() && "Register number out of range!");
00066     return RegsBegin[i];
00067   }
00068 
00069   /// contains - Return true if the specified register is included in this
00070   /// register class.  This does not include virtual registers.
00071   bool contains(unsigned Reg) const {
00072     unsigned InByte = Reg % 8;
00073     unsigned Byte = Reg / 8;
00074     if (Byte >= RegSetSize)
00075       return false;
00076     return (RegSet[Byte] & (1 << InByte)) != 0;
00077   }
00078 
00079   /// contains - Return true if both registers are in this class.
00080   bool contains(unsigned Reg1, unsigned Reg2) const {
00081     return contains(Reg1) && contains(Reg2);
00082   }
00083 
00084   /// getSize - Return the size of the register in bytes, which is also the size
00085   /// of a stack slot allocated to hold a spilled copy of this register.
00086   unsigned getSize() const { return RegSize; }
00087 
00088   /// getAlignment - Return the minimum required alignment for a register of
00089   /// this class.
00090   unsigned getAlignment() const { return Alignment; }
00091 
00092   /// getCopyCost - Return the cost of copying a value between two registers in
00093   /// this class. A negative number means the register class is very expensive
00094   /// to copy e.g. status flag register classes.
00095   int getCopyCost() const { return CopyCost; }
00096 
00097   /// isAllocatable - Return true if this register class may be used to create
00098   /// virtual registers.
00099   bool isAllocatable() const { return Allocatable; }
00100 };
00101 
00102 /// MCRegisterDesc - This record contains information about a particular
00103 /// register.  The SubRegs field is a zero terminated array of registers that
00104 /// are sub-registers of the specific register, e.g. AL, AH are sub-registers
00105 /// of AX. The SuperRegs field is a zero terminated array of registers that are
00106 /// super-registers of the specific register, e.g. RAX, EAX, are
00107 /// super-registers of AX.
00108 ///
00109 struct MCRegisterDesc {
00110   uint32_t Name;      // Printable name for the reg (for debugging)
00111   uint32_t SubRegs;   // Sub-register set, described above
00112   uint32_t SuperRegs; // Super-register set, described above
00113 
00114   // Offset into MCRI::SubRegIndices of a list of sub-register indices for each
00115   // sub-register in SubRegs.
00116   uint32_t SubRegIndices;
00117 
00118   // RegUnits - Points to the list of register units. The low 4 bits holds the
00119   // Scale, the high bits hold an offset into DiffLists. See MCRegUnitIterator.
00120   uint32_t RegUnits;
00121 };
00122 
00123 /// MCRegisterInfo base class - We assume that the target defines a static
00124 /// array of MCRegisterDesc objects that represent all of the machine
00125 /// registers that the target has.  As such, we simply have to track a pointer
00126 /// to this array so that we can turn register number into a register
00127 /// descriptor.
00128 ///
00129 /// Note this class is designed to be a base class of TargetRegisterInfo, which
00130 /// is the interface used by codegen. However, specific targets *should never*
00131 /// specialize this class. MCRegisterInfo should only contain getters to access
00132 /// TableGen generated physical register data. It must not be extended with
00133 /// virtual methods.
00134 ///
00135 class MCRegisterInfo {
00136 public:
00137   typedef const MCRegisterClass *regclass_iterator;
00138 
00139   /// DwarfLLVMRegPair - Emitted by tablegen so Dwarf<->LLVM reg mappings can be
00140   /// performed with a binary search.
00141   struct DwarfLLVMRegPair {
00142     unsigned FromReg;
00143     unsigned ToReg;
00144 
00145     bool operator<(DwarfLLVMRegPair RHS) const { return FromReg < RHS.FromReg; }
00146   };
00147 
00148   /// SubRegCoveredBits - Emitted by tablegen: bit range covered by a subreg
00149   /// index, -1 in any being invalid.
00150   struct SubRegCoveredBits {
00151     uint16_t Offset;
00152     uint16_t Size;
00153   };
00154 private:
00155   const MCRegisterDesc *Desc;                 // Pointer to the descriptor array
00156   unsigned NumRegs;                           // Number of entries in the array
00157   unsigned RAReg;                             // Return address register
00158   unsigned PCReg;                             // Program counter register
00159   const MCRegisterClass *Classes;             // Pointer to the regclass array
00160   unsigned NumClasses;                        // Number of entries in the array
00161   unsigned NumRegUnits;                       // Number of regunits.
00162   const MCPhysReg (*RegUnitRoots)[2];         // Pointer to regunit root table.
00163   const MCPhysReg *DiffLists;                 // Pointer to the difflists array
00164   const char *RegStrings;                     // Pointer to the string table.
00165   const uint16_t *SubRegIndices;              // Pointer to the subreg lookup
00166                                               // array.
00167   const SubRegCoveredBits *SubRegIdxRanges;   // Pointer to the subreg covered
00168                                               // bit ranges array.
00169   unsigned NumSubRegIndices;                  // Number of subreg indices.
00170   const uint16_t *RegEncodingTable;           // Pointer to array of register
00171                                               // encodings.
00172 
00173   unsigned L2DwarfRegsSize;
00174   unsigned EHL2DwarfRegsSize;
00175   unsigned Dwarf2LRegsSize;
00176   unsigned EHDwarf2LRegsSize;
00177   const DwarfLLVMRegPair *L2DwarfRegs;        // LLVM to Dwarf regs mapping
00178   const DwarfLLVMRegPair *EHL2DwarfRegs;      // LLVM to Dwarf regs mapping EH
00179   const DwarfLLVMRegPair *Dwarf2LRegs;        // Dwarf to LLVM regs mapping
00180   const DwarfLLVMRegPair *EHDwarf2LRegs;      // Dwarf to LLVM regs mapping EH
00181   DenseMap<unsigned, int> L2SEHRegs;          // LLVM to SEH regs mapping
00182 
00183 public:
00184   /// DiffListIterator - Base iterator class that can traverse the
00185   /// differentially encoded register and regunit lists in DiffLists.
00186   /// Don't use this class directly, use one of the specialized sub-classes
00187   /// defined below.
00188   class DiffListIterator {
00189     uint16_t Val;
00190     const MCPhysReg *List;
00191 
00192   protected:
00193     /// Create an invalid iterator. Call init() to point to something useful.
00194     DiffListIterator() : Val(0), List(nullptr) {}
00195 
00196     /// init - Point the iterator to InitVal, decoding subsequent values from
00197     /// DiffList. The iterator will initially point to InitVal, sub-classes are
00198     /// responsible for skipping the seed value if it is not part of the list.
00199     void init(MCPhysReg InitVal, const MCPhysReg *DiffList) {
00200       Val = InitVal;
00201       List = DiffList;
00202     }
00203 
00204     /// advance - Move to the next list position, return the applied
00205     /// differential. This function does not detect the end of the list, that
00206     /// is the caller's responsibility (by checking for a 0 return value).
00207     unsigned advance() {
00208       assert(isValid() && "Cannot move off the end of the list.");
00209       MCPhysReg D = *List++;
00210       Val += D;
00211       return D;
00212     }
00213 
00214   public:
00215 
00216     /// isValid - returns true if this iterator is not yet at the end.
00217     bool isValid() const { return List; }
00218 
00219     /// Dereference the iterator to get the value at the current position.
00220     unsigned operator*() const { return Val; }
00221 
00222     /// Pre-increment to move to the next position.
00223     void operator++() {
00224       // The end of the list is encoded as a 0 differential.
00225       if (!advance())
00226         List = nullptr;
00227     }
00228   };
00229 
00230   // These iterators are allowed to sub-class DiffListIterator and access
00231   // internal list pointers.
00232   friend class MCSubRegIterator;
00233   friend class MCSuperRegIterator;
00234   friend class MCRegUnitIterator;
00235   friend class MCRegUnitRootIterator;
00236 
00237   /// \brief Initialize MCRegisterInfo, called by TableGen
00238   /// auto-generated routines. *DO NOT USE*.
00239   void InitMCRegisterInfo(const MCRegisterDesc *D, unsigned NR, unsigned RA,
00240                           unsigned PC,
00241                           const MCRegisterClass *C, unsigned NC,
00242                           const MCPhysReg (*RURoots)[2],
00243                           unsigned NRU,
00244                           const MCPhysReg *DL,
00245                           const char *Strings,
00246                           const uint16_t *SubIndices,
00247                           unsigned NumIndices,
00248                           const SubRegCoveredBits *SubIdxRanges,
00249                           const uint16_t *RET) {
00250     Desc = D;
00251     NumRegs = NR;
00252     RAReg = RA;
00253     PCReg = PC;
00254     Classes = C;
00255     DiffLists = DL;
00256     RegStrings = Strings;
00257     NumClasses = NC;
00258     RegUnitRoots = RURoots;
00259     NumRegUnits = NRU;
00260     SubRegIndices = SubIndices;
00261     NumSubRegIndices = NumIndices;
00262     SubRegIdxRanges = SubIdxRanges;
00263     RegEncodingTable = RET;
00264   }
00265 
00266   /// \brief Used to initialize LLVM register to Dwarf
00267   /// register number mapping. Called by TableGen auto-generated routines.
00268   /// *DO NOT USE*.
00269   void mapLLVMRegsToDwarfRegs(const DwarfLLVMRegPair *Map, unsigned Size,
00270                               bool isEH) {
00271     if (isEH) {
00272       EHL2DwarfRegs = Map;
00273       EHL2DwarfRegsSize = Size;
00274     } else {
00275       L2DwarfRegs = Map;
00276       L2DwarfRegsSize = Size;
00277     }
00278   }
00279 
00280   /// \brief Used to initialize Dwarf register to LLVM
00281   /// register number mapping. Called by TableGen auto-generated routines.
00282   /// *DO NOT USE*.
00283   void mapDwarfRegsToLLVMRegs(const DwarfLLVMRegPair *Map, unsigned Size,
00284                               bool isEH) {
00285     if (isEH) {
00286       EHDwarf2LRegs = Map;
00287       EHDwarf2LRegsSize = Size;
00288     } else {
00289       Dwarf2LRegs = Map;
00290       Dwarf2LRegsSize = Size;
00291     }
00292   }
00293 
00294   /// mapLLVMRegToSEHReg - Used to initialize LLVM register to SEH register
00295   /// number mapping. By default the SEH register number is just the same
00296   /// as the LLVM register number.
00297   /// FIXME: TableGen these numbers. Currently this requires target specific
00298   /// initialization code.
00299   void mapLLVMRegToSEHReg(unsigned LLVMReg, int SEHReg) {
00300     L2SEHRegs[LLVMReg] = SEHReg;
00301   }
00302 
00303   /// \brief This method should return the register where the return
00304   /// address can be found.
00305   unsigned getRARegister() const {
00306     return RAReg;
00307   }
00308 
00309   /// Return the register which is the program counter.
00310   unsigned getProgramCounter() const {
00311     return PCReg;
00312   }
00313 
00314   const MCRegisterDesc &operator[](unsigned RegNo) const {
00315     assert(RegNo < NumRegs &&
00316            "Attempting to access record for invalid register number!");
00317     return Desc[RegNo];
00318   }
00319 
00320   /// \brief Provide a get method, equivalent to [], but more useful with a
00321   /// pointer to this object.
00322   const MCRegisterDesc &get(unsigned RegNo) const {
00323     return operator[](RegNo);
00324   }
00325 
00326   /// \brief Returns the physical register number of sub-register "Index"
00327   /// for physical register RegNo. Return zero if the sub-register does not
00328   /// exist.
00329   unsigned getSubReg(unsigned Reg, unsigned Idx) const;
00330 
00331   /// \brief Return a super-register of the specified register
00332   /// Reg so its sub-register of index SubIdx is Reg.
00333   unsigned getMatchingSuperReg(unsigned Reg, unsigned SubIdx,
00334                                const MCRegisterClass *RC) const;
00335 
00336   /// \brief For a given register pair, return the sub-register index
00337   /// if the second register is a sub-register of the first. Return zero
00338   /// otherwise.
00339   unsigned getSubRegIndex(unsigned RegNo, unsigned SubRegNo) const;
00340 
00341   /// \brief Get the size of the bit range covered by a sub-register index.
00342   /// If the index isn't continuous, return the sum of the sizes of its parts.
00343   /// If the index is used to access subregisters of different sizes, return -1.
00344   unsigned getSubRegIdxSize(unsigned Idx) const;
00345 
00346   /// \brief Get the offset of the bit range covered by a sub-register index.
00347   /// If an Offset doesn't make sense (the index isn't continuous, or is used to
00348   /// access sub-registers at different offsets), return -1.
00349   unsigned getSubRegIdxOffset(unsigned Idx) const;
00350 
00351   /// \brief Return the human-readable symbolic target-specific name for the
00352   /// specified physical register.
00353   const char *getName(unsigned RegNo) const {
00354     return RegStrings + get(RegNo).Name;
00355   }
00356 
00357   /// \brief Return the number of registers this target has (useful for
00358   /// sizing arrays holding per register information)
00359   unsigned getNumRegs() const {
00360     return NumRegs;
00361   }
00362 
00363   /// \brief Return the number of sub-register indices
00364   /// understood by the target. Index 0 is reserved for the no-op sub-register,
00365   /// while 1 to getNumSubRegIndices() - 1 represent real sub-registers.
00366   unsigned getNumSubRegIndices() const {
00367     return NumSubRegIndices;
00368   }
00369 
00370   /// \brief Return the number of (native) register units in the
00371   /// target. Register units are numbered from 0 to getNumRegUnits() - 1. They
00372   /// can be accessed through MCRegUnitIterator defined below.
00373   unsigned getNumRegUnits() const {
00374     return NumRegUnits;
00375   }
00376 
00377   /// \brief Map a target register to an equivalent dwarf register
00378   /// number.  Returns -1 if there is no equivalent value.  The second
00379   /// parameter allows targets to use different numberings for EH info and
00380   /// debugging info.
00381   int getDwarfRegNum(unsigned RegNum, bool isEH) const;
00382 
00383   /// \brief Map a dwarf register back to a target register.
00384   int getLLVMRegNum(unsigned RegNum, bool isEH) const;
00385 
00386   /// \brief Map a target register to an equivalent SEH register
00387   /// number.  Returns LLVM register number if there is no equivalent value.
00388   int getSEHRegNum(unsigned RegNum) const;
00389 
00390   regclass_iterator regclass_begin() const { return Classes; }
00391   regclass_iterator regclass_end() const { return Classes+NumClasses; }
00392 
00393   unsigned getNumRegClasses() const {
00394     return (unsigned)(regclass_end()-regclass_begin());
00395   }
00396 
00397   /// \brief Returns the register class associated with the enumeration
00398   /// value.  See class MCOperandInfo.
00399   const MCRegisterClass& getRegClass(unsigned i) const {
00400     assert(i < getNumRegClasses() && "Register Class ID out of range");
00401     return Classes[i];
00402   }
00403 
00404    /// \brief Returns the encoding for RegNo
00405   uint16_t getEncodingValue(unsigned RegNo) const {
00406     assert(RegNo < NumRegs &&
00407            "Attempting to get encoding for invalid register number!");
00408     return RegEncodingTable[RegNo];
00409   }
00410 
00411   /// \brief Returns true if RegB is a sub-register of RegA.
00412   bool isSubRegister(unsigned RegA, unsigned RegB) const {
00413     return isSuperRegister(RegB, RegA);
00414   }
00415 
00416   /// \brief Returns true if RegB is a super-register of RegA.
00417   bool isSuperRegister(unsigned RegA, unsigned RegB) const;
00418 
00419   /// \brief Returns true if RegB is a sub-register of RegA or if RegB == RegA.
00420   bool isSubRegisterEq(unsigned RegA, unsigned RegB) const {
00421     return isSuperRegisterEq(RegB, RegA);
00422   }
00423 
00424   /// \brief Returns true if RegB is a super-register of RegA or if
00425   /// RegB == RegA.
00426   bool isSuperRegisterEq(unsigned RegA, unsigned RegB) const {
00427     return RegA == RegB || isSuperRegister(RegA, RegB);
00428   }
00429 
00430 };
00431 
00432 //===----------------------------------------------------------------------===//
00433 //                          Register List Iterators
00434 //===----------------------------------------------------------------------===//
00435 
00436 // MCRegisterInfo provides lists of super-registers, sub-registers, and
00437 // aliasing registers. Use these iterator classes to traverse the lists.
00438 
00439 /// MCSubRegIterator enumerates all sub-registers of Reg.
00440 /// If IncludeSelf is set, Reg itself is included in the list.
00441 class MCSubRegIterator : public MCRegisterInfo::DiffListIterator {
00442 public:
00443   MCSubRegIterator(unsigned Reg, const MCRegisterInfo *MCRI,
00444                      bool IncludeSelf = false) {
00445     init(Reg, MCRI->DiffLists + MCRI->get(Reg).SubRegs);
00446     // Initially, the iterator points to Reg itself.
00447     if (!IncludeSelf)
00448       ++*this;
00449   }
00450 };
00451 
00452 /// MCSuperRegIterator enumerates all super-registers of Reg.
00453 /// If IncludeSelf is set, Reg itself is included in the list.
00454 class MCSuperRegIterator : public MCRegisterInfo::DiffListIterator {
00455 public:
00456   MCSuperRegIterator() {}
00457   MCSuperRegIterator(unsigned Reg, const MCRegisterInfo *MCRI,
00458                      bool IncludeSelf = false) {
00459     init(Reg, MCRI->DiffLists + MCRI->get(Reg).SuperRegs);
00460     // Initially, the iterator points to Reg itself.
00461     if (!IncludeSelf)
00462       ++*this;
00463   }
00464 };
00465 
00466 // Definition for isSuperRegister. Put it down here since it needs the
00467 // iterator defined above in addition to the MCRegisterInfo class itself.
00468 inline bool MCRegisterInfo::isSuperRegister(unsigned RegA, unsigned RegB) const{
00469   for (MCSuperRegIterator I(RegA, this); I.isValid(); ++I)
00470     if (*I == RegB)
00471       return true;
00472   return false;
00473 }
00474 
00475 //===----------------------------------------------------------------------===//
00476 //                               Register Units
00477 //===----------------------------------------------------------------------===//
00478 
00479 // Register units are used to compute register aliasing. Every register has at
00480 // least one register unit, but it can have more. Two registers overlap if and
00481 // only if they have a common register unit.
00482 //
00483 // A target with a complicated sub-register structure will typically have many
00484 // fewer register units than actual registers. MCRI::getNumRegUnits() returns
00485 // the number of register units in the target.
00486 
00487 // MCRegUnitIterator enumerates a list of register units for Reg. The list is
00488 // in ascending numerical order.
00489 class MCRegUnitIterator : public MCRegisterInfo::DiffListIterator {
00490 public:
00491   /// MCRegUnitIterator - Create an iterator that traverses the register units
00492   /// in Reg.
00493   MCRegUnitIterator() {}
00494   MCRegUnitIterator(unsigned Reg, const MCRegisterInfo *MCRI) {
00495     assert(Reg && "Null register has no regunits");
00496     // Decode the RegUnits MCRegisterDesc field.
00497     unsigned RU = MCRI->get(Reg).RegUnits;
00498     unsigned Scale = RU & 15;
00499     unsigned Offset = RU >> 4;
00500 
00501     // Initialize the iterator to Reg * Scale, and the List pointer to
00502     // DiffLists + Offset.
00503     init(Reg * Scale, MCRI->DiffLists + Offset);
00504 
00505     // That may not be a valid unit, we need to advance by one to get the real
00506     // unit number. The first differential can be 0 which would normally
00507     // terminate the list, but since we know every register has at least one
00508     // unit, we can allow a 0 differential here.
00509     advance();
00510   }
00511 };
00512 
00513 // Each register unit has one or two root registers. The complete set of
00514 // registers containing a register unit is the union of the roots and their
00515 // super-registers. All registers aliasing Unit can be visited like this:
00516 //
00517 //   for (MCRegUnitRootIterator RI(Unit, MCRI); RI.isValid(); ++RI) {
00518 //     for (MCSuperRegIterator SI(*RI, MCRI, true); SI.isValid(); ++SI)
00519 //       visit(*SI);
00520 //    }
00521 
00522 /// MCRegUnitRootIterator enumerates the root registers of a register unit.
00523 class MCRegUnitRootIterator {
00524   uint16_t Reg0;
00525   uint16_t Reg1;
00526 public:
00527   MCRegUnitRootIterator() : Reg0(0), Reg1(0) {}
00528   MCRegUnitRootIterator(unsigned RegUnit, const MCRegisterInfo *MCRI) {
00529     assert(RegUnit < MCRI->getNumRegUnits() && "Invalid register unit");
00530     Reg0 = MCRI->RegUnitRoots[RegUnit][0];
00531     Reg1 = MCRI->RegUnitRoots[RegUnit][1];
00532   }
00533 
00534   /// \brief Dereference to get the current root register.
00535   unsigned operator*() const {
00536     return Reg0;
00537   }
00538 
00539   /// \brief Check if the iterator is at the end of the list.
00540   bool isValid() const {
00541     return Reg0;
00542   }
00543 
00544   /// \brief Preincrement to move to the next root register.
00545   void operator++() {
00546     assert(isValid() && "Cannot move off the end of the list.");
00547     Reg0 = Reg1;
00548     Reg1 = 0;
00549   }
00550 };
00551 
00552 /// MCRegAliasIterator enumerates all registers aliasing Reg.  If IncludeSelf is
00553 /// set, Reg itself is included in the list.  This iterator does not guarantee
00554 /// any ordering or that entries are unique.
00555 class MCRegAliasIterator {
00556 private:
00557   unsigned Reg;
00558   const MCRegisterInfo *MCRI;
00559   bool IncludeSelf;
00560   
00561   MCRegUnitIterator RI;
00562   MCRegUnitRootIterator RRI;
00563   MCSuperRegIterator SI;
00564 public:
00565   MCRegAliasIterator(unsigned Reg, const MCRegisterInfo *MCRI,
00566                      bool IncludeSelf)
00567     : Reg(Reg), MCRI(MCRI), IncludeSelf(IncludeSelf) {
00568 
00569     // Initialize the iterators.
00570     for (RI = MCRegUnitIterator(Reg, MCRI); RI.isValid(); ++RI) {
00571       for (RRI = MCRegUnitRootIterator(*RI, MCRI); RRI.isValid(); ++RRI) {
00572         for (SI = MCSuperRegIterator(*RRI, MCRI, true); SI.isValid(); ++SI) {
00573           if (!(!IncludeSelf && Reg == *SI))
00574             return;
00575         }
00576       }
00577     }
00578   }
00579 
00580   bool isValid() const {
00581     return RI.isValid();
00582   }
00583   
00584   unsigned operator*() const {
00585     assert (SI.isValid() && "Cannot dereference an invalid iterator.");
00586     return *SI;
00587   }
00588 
00589   void advance() {
00590     // Assuming SI is valid.
00591     ++SI;
00592     if (SI.isValid()) return;
00593 
00594     ++RRI;
00595     if (RRI.isValid()) {
00596       SI = MCSuperRegIterator(*RRI, MCRI, true);
00597       return;
00598     }
00599 
00600     ++RI;
00601     if (RI.isValid()) {
00602       RRI = MCRegUnitRootIterator(*RI, MCRI);
00603       SI = MCSuperRegIterator(*RRI, MCRI, true);
00604     }
00605   }
00606 
00607   void operator++() {
00608     assert(isValid() && "Cannot move off the end of the list.");
00609     do advance();
00610     while (!IncludeSelf && isValid() && *SI == Reg);
00611   }
00612 };
00613 
00614 } // End llvm namespace
00615 
00616 #endif