[TargetRegisterInfo] Refactor the code to use BitMaskClassIterator.

llvm-svn: 265734
This commit is contained in:
Quentin Colombet 2016-04-07 22:16:56 +00:00
parent cf477ffc58
commit 2445dc1916
1 changed files with 5 additions and 12 deletions

View File

@ -112,18 +112,11 @@ TargetRegisterInfo::getAllocatableClass(const TargetRegisterClass *RC) const {
if (!RC || RC->isAllocatable())
return RC;
const unsigned *SubClass = RC->getSubClassMask();
for (unsigned Base = 0, BaseE = getNumRegClasses();
Base < BaseE; Base += 32) {
unsigned Idx = Base;
for (unsigned Mask = *SubClass++; Mask; Mask >>= 1) {
unsigned Offset = countTrailingZeros(Mask);
const TargetRegisterClass *SubRC = getRegClass(Idx + Offset);
if (SubRC->isAllocatable())
return SubRC;
Mask >>= Offset;
Idx += Offset + 1;
}
for (BitMaskClassIterator It(RC->getSubClassMask(), *this); It.isValid();
++It) {
const TargetRegisterClass *SubRC = getRegClass(It.getID());
if (SubRC->isAllocatable())
return SubRC;
}
return nullptr;
}