diff options
author | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2012-05-30 16:36:28 +0000 |
---|---|---|
committer | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2012-05-30 16:36:28 +0000 |
commit | cd00ef033cf944fc96a0d06ffcf49cd805fc4ee3 (patch) | |
tree | 0b2b4bab850900a04cdac7aedc35c3e91af40caf | |
parent | 1afbd278d10a24803491015a5f50508f3ab422e7 (diff) |
Add MCRegisterInfo::RegListIterator.
Also add subclasses MCSubRegIterator, MCSuperRegIterator, and
MCRegAliasIterator.
These iterators provide an abstract interface to the MCRegisterInfo
register lists so the internal representation can be changed without
changing all clients.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@157695 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/MC/MCRegisterInfo.h | 56 | ||||
-rw-r--r-- | include/llvm/Target/TargetRegisterInfo.h | 8 |
2 files changed, 58 insertions, 6 deletions
diff --git a/include/llvm/MC/MCRegisterInfo.h b/include/llvm/MC/MCRegisterInfo.h index 364f9e5db4..1a15424108 100644 --- a/include/llvm/MC/MCRegisterInfo.h +++ b/include/llvm/MC/MCRegisterInfo.h @@ -167,6 +167,25 @@ private: DenseMap<unsigned, int> L2SEHRegs; // LLVM to SEH regs mapping public: + /// RegListIterator. This iterator class is used to traverse lists of + /// super-registers, sub-registers, and overlapping registers. Don't use it + /// directly, use one of the sub-classes defined below. + class RegListIterator { + const uint16_t *Pos; + public: + explicit RegListIterator(const uint16_t *Table) + : Pos(Table) {} + + /// isValid - Return false when the end of the list is reached. + bool isValid() const { return *Pos; } + + /// Dereference the iterator to get the current register. + unsigned operator*() const { return *Pos; } + + /// Pre-increment. Move to the next register. + void operator++() { ++Pos; } + }; + /// DiffListIterator - Base iterator class that can traverse the /// differentially encoded register and regunit lists in DiffLists. /// Don't use this class directly, use one of the specialized sub-classes @@ -213,8 +232,11 @@ public: } }; - // These iterators are allowed to sub-class DiffListIterator and access - // internal list pointers. + // These iterators are allowed to sub-class RegListIterator and + // DiffListIterator and access internal list pointers. + friend class MCSubRegIterator; + friend class MCSuperRegIterator; + friend class MCRegAliasIterator; friend class MCRegUnitIterator; /// InitMCRegisterInfo - Initialize MCRegisterInfo, called by TableGen @@ -438,6 +460,36 @@ public: }; //===----------------------------------------------------------------------===// +// Register List Iterators +//===----------------------------------------------------------------------===// + +// MCRegisterInfo provides lists of super-registers, sub-registers, and +// aliasing registers. Use these iterator classes to traverse the lists. + +/// MCSubRegIterator enumerates all sub-registers of Reg. +class MCSubRegIterator : public MCRegisterInfo::RegListIterator { +public: + MCSubRegIterator(unsigned Reg, const MCRegisterInfo *MCRI) + : RegListIterator(MCRI->RegLists + MCRI->get(Reg).SubRegs) {} +}; + +/// MCSuperRegIterator enumerates all super-registers of Reg. +class MCSuperRegIterator : public MCRegisterInfo::RegListIterator { +public: + MCSuperRegIterator(unsigned Reg, const MCRegisterInfo *MCRI) + : RegListIterator(MCRI->RegLists + MCRI->get(Reg).SuperRegs) {} +}; + +/// MCRegAliasIterator enumerates all registers aliasing Reg. +/// If IncludeSelf is set, Reg itself is included in the list. +class MCRegAliasIterator : public MCRegisterInfo::RegListIterator { +public: + MCRegAliasIterator(unsigned Reg, const MCRegisterInfo *MCRI, bool IncludeSelf) + : RegListIterator(MCRI->RegLists + MCRI->get(Reg).Overlaps + !IncludeSelf) + {} +}; + +//===----------------------------------------------------------------------===// // Register Units //===----------------------------------------------------------------------===// diff --git a/include/llvm/Target/TargetRegisterInfo.h b/include/llvm/Target/TargetRegisterInfo.h index 949fce8461..b792889db8 100644 --- a/include/llvm/Target/TargetRegisterInfo.h +++ b/include/llvm/Target/TargetRegisterInfo.h @@ -357,10 +357,10 @@ public: /// isSuperRegister - Returns true if regB is a super-register of regA. /// - bool isSuperRegister(unsigned regA, unsigned regB) const { - for (const uint16_t *regList = getSuperRegisters(regA); *regList;++regList){ - if (*regList == regB) return true; - } + bool isSuperRegister(unsigned RegA, unsigned RegB) const { + for (MCSuperRegIterator I(RegA, this); I.isValid(); ++I) + if (*I == RegB) + return true; return false; } |