Skip to content

Commit 2fd37c9

Browse files
authored
[TableGen] Remove RegUnitIterator. NFC. (#147483)
TableGen's RegUnitIterator is a strange contraption that iterates over a range of registers as well as the regunits of each register. Since it is only used in one place in a `for` loop, it is much simpler to use two nested loops instead.
1 parent 5cefb9a commit 2fd37c9

File tree

1 file changed

+6
-60
lines changed

1 file changed

+6
-60
lines changed

llvm/utils/TableGen/Common/CodeGenRegisters.cpp

Lines changed: 6 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -200,62 +200,6 @@ void CodeGenRegister::buildObjectGraph(CodeGenRegBank &RegBank) {
200200
}
201201
}
202202

203-
namespace {
204-
205-
// Iterate over all register units in a set of registers.
206-
class RegUnitIterator {
207-
CodeGenRegister::Vec::const_iterator RegI, RegE;
208-
CodeGenRegister::RegUnitList::iterator UnitI, UnitE;
209-
static CodeGenRegister::RegUnitList Sentinel;
210-
211-
public:
212-
RegUnitIterator(const CodeGenRegister::Vec &Regs)
213-
: RegI(Regs.begin()), RegE(Regs.end()) {
214-
215-
if (RegI == RegE) {
216-
UnitI = Sentinel.end();
217-
UnitE = Sentinel.end();
218-
} else {
219-
UnitI = (*RegI)->getRegUnits().begin();
220-
UnitE = (*RegI)->getRegUnits().end();
221-
advance();
222-
}
223-
}
224-
225-
bool isValid() const { return UnitI != UnitE; }
226-
227-
unsigned operator*() const {
228-
assert(isValid());
229-
return *UnitI;
230-
}
231-
232-
const CodeGenRegister *getReg() const {
233-
assert(isValid());
234-
return *RegI;
235-
}
236-
237-
/// Preincrement. Move to the next unit.
238-
void operator++() {
239-
assert(isValid() && "Cannot advance beyond the last operand");
240-
++UnitI;
241-
advance();
242-
}
243-
244-
protected:
245-
void advance() {
246-
while (UnitI == UnitE) {
247-
if (++RegI == RegE)
248-
break;
249-
UnitI = (*RegI)->getRegUnits().begin();
250-
UnitE = (*RegI)->getRegUnits().end();
251-
}
252-
}
253-
};
254-
255-
CodeGenRegister::RegUnitList RegUnitIterator::Sentinel;
256-
257-
} // end anonymous namespace
258-
259203
// Inherit register units from subregisters.
260204
// Return true if the RegUnits changed.
261205
bool CodeGenRegister::inheritRegUnits(CodeGenRegBank &RegBank) {
@@ -1131,10 +1075,12 @@ void CodeGenRegisterClass::getSuperRegClasses(const CodeGenSubRegIndex *SubIdx,
11311075
void CodeGenRegisterClass::buildRegUnitSet(
11321076
const CodeGenRegBank &RegBank, std::vector<unsigned> &RegUnits) const {
11331077
std::vector<unsigned> TmpUnits;
1134-
for (RegUnitIterator UnitI(Members); UnitI.isValid(); ++UnitI) {
1135-
const RegUnit &RU = RegBank.getRegUnit(*UnitI);
1136-
if (!RU.Artificial)
1137-
TmpUnits.push_back(*UnitI);
1078+
for (const CodeGenRegister *Reg : Members) {
1079+
for (unsigned UnitI : Reg->getRegUnits()) {
1080+
const RegUnit &RU = RegBank.getRegUnit(UnitI);
1081+
if (!RU.Artificial)
1082+
TmpUnits.push_back(UnitI);
1083+
}
11381084
}
11391085
llvm::sort(TmpUnits);
11401086
std::unique_copy(TmpUnits.begin(), TmpUnits.end(),

0 commit comments

Comments
 (0)