Skip to content

Commit d1cc137

Browse files
authored
[CodeGen] Add TRI::regunits() iterating over all register units (NFC) (llvm#167901)
1 parent 8d6a1de commit d1cc137

File tree

6 files changed

+18
-11
lines changed

6 files changed

+18
-11
lines changed

llvm/include/llvm/MC/MCRegisterInfo.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define LLVM_MC_MCREGISTERINFO_H
1717

1818
#include "llvm/ADT/DenseMap.h"
19+
#include "llvm/ADT/Sequence.h"
1920
#include "llvm/ADT/iterator.h"
2021
#include "llvm/ADT/iterator_range.h"
2122
#include "llvm/MC/LaneBitmask.h"
@@ -259,6 +260,9 @@ class LLVM_ABI MCRegisterInfo {
259260
iterator_range<MCSuperRegIterator>>
260261
sub_and_superregs_inclusive(MCRegister Reg) const;
261262

263+
/// Returns an iterator range over all regunits.
264+
iota_range<MCRegUnit> regunits() const;
265+
262266
/// Returns an iterator range over all regunits for \p Reg.
263267
iterator_range<MCRegUnitIterator> regunits(MCRegister Reg) const;
264268

@@ -798,6 +802,10 @@ MCRegisterInfo::sub_and_superregs_inclusive(MCRegister Reg) const {
798802
return concat<const MCPhysReg>(subregs_inclusive(Reg), superregs(Reg));
799803
}
800804

805+
inline iota_range<MCRegUnit> MCRegisterInfo::regunits() const {
806+
return seq(getNumRegUnits());
807+
}
808+
801809
inline iterator_range<MCRegUnitIterator>
802810
MCRegisterInfo::regunits(MCRegister Reg) const {
803811
return make_range({Reg, this}, MCRegUnitIterator());

llvm/lib/CodeGen/LiveIntervals.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ void LiveIntervals::analyze(MachineFunction &fn) {
173173
if (EnablePrecomputePhysRegs) {
174174
// For stress testing, precompute live ranges of all physical register
175175
// units, including reserved registers.
176-
for (unsigned i = 0, e = TRI->getNumRegUnits(); i != e; ++i)
177-
getRegUnit(i);
176+
for (MCRegUnit Unit : TRI->regunits())
177+
getRegUnit(Unit);
178178
}
179179
}
180180

llvm/lib/CodeGen/LiveRegUnits.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
using namespace llvm;
2121

2222
void LiveRegUnits::removeRegsNotPreserved(const uint32_t *RegMask) {
23-
for (unsigned U = 0, E = TRI->getNumRegUnits(); U != E; ++U) {
23+
for (MCRegUnit U : TRI->regunits()) {
2424
for (MCRegUnitRootIterator RootReg(U, TRI); RootReg.isValid(); ++RootReg) {
2525
if (MachineOperand::clobbersPhysReg(RegMask, *RootReg)) {
2626
Units.reset(U);
@@ -31,7 +31,7 @@ void LiveRegUnits::removeRegsNotPreserved(const uint32_t *RegMask) {
3131
}
3232

3333
void LiveRegUnits::addRegsInMask(const uint32_t *RegMask) {
34-
for (unsigned U = 0, E = TRI->getNumRegUnits(); U != E; ++U) {
34+
for (MCRegUnit U : TRI->regunits()) {
3535
for (MCRegUnitRootIterator RootReg(U, TRI); RootReg.isValid(); ++RootReg) {
3636
if (MachineOperand::clobbersPhysReg(RegMask, *RootReg)) {
3737
Units.set(U);

llvm/lib/CodeGen/MachineVerifier.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3564,9 +3564,9 @@ void MachineVerifier::verifyLiveIntervals() {
35643564
}
35653565

35663566
// Verify all the cached regunit intervals.
3567-
for (unsigned i = 0, e = TRI->getNumRegUnits(); i != e; ++i)
3568-
if (const LiveRange *LR = LiveInts->getCachedRegUnit(i))
3569-
verifyLiveRange(*LR, VirtRegOrUnit(i));
3567+
for (MCRegUnit Unit : TRI->regunits())
3568+
if (const LiveRange *LR = LiveInts->getCachedRegUnit(Unit))
3569+
verifyLiveRange(*LR, VirtRegOrUnit(Unit));
35703570
}
35713571

35723572
void MachineVerifier::verifyLiveRangeValue(const LiveRange &LR,

llvm/lib/CodeGen/RDFRegisters.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ PhysicalRegisterInfo::PhysicalRegisterInfo(const TargetRegisterInfo &tri,
4646

4747
UnitInfos.resize(TRI.getNumRegUnits());
4848

49-
for (uint32_t U = 0, NU = TRI.getNumRegUnits(); U != NU; ++U) {
49+
for (MCRegUnit U : TRI.regunits()) {
5050
if (UnitInfos[U].Reg != 0)
5151
continue;
5252
MCRegUnitRootIterator R(U, &TRI);
@@ -88,7 +88,7 @@ PhysicalRegisterInfo::PhysicalRegisterInfo(const TargetRegisterInfo &tri,
8888
}
8989

9090
AliasInfos.resize(TRI.getNumRegUnits());
91-
for (uint32_t U = 0, NU = TRI.getNumRegUnits(); U != NU; ++U) {
91+
for (MCRegUnit U : TRI.regunits()) {
9292
BitVector AS(TRI.getNumRegs());
9393
for (MCRegUnitRootIterator R(U, &TRI); R.isValid(); ++R)
9494
for (MCPhysReg S : TRI.superregs_inclusive(*R))

llvm/lib/CodeGen/RegAllocFast.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,8 +1291,7 @@ bool RegAllocFastImpl::setPhysReg(MachineInstr &MI, MachineOperand &MO,
12911291
#ifndef NDEBUG
12921292

12931293
void RegAllocFastImpl::dumpState() const {
1294-
for (unsigned Unit = 1, UnitE = TRI->getNumRegUnits(); Unit != UnitE;
1295-
++Unit) {
1294+
for (MCRegUnit Unit : TRI->regunits()) {
12961295
switch (unsigned VirtReg = RegUnitStates[Unit]) {
12971296
case regFree:
12981297
break;

0 commit comments

Comments
 (0)