Skip to content

Commit 12edc56

Browse files
authored
[RegAllocFast] Add helper methods for getting/setting regunit state(NFC) (#167931)
The methods will help reduce the number of static_casts after changing MCRegUnit to a strong typedef.
1 parent 1b723f2 commit 12edc56

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

llvm/lib/CodeGen/RegAllocFast.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ class RegAllocFastImpl {
275275
// Assign index for each instruction to quickly determine dominance.
276276
InstrPosIndexes PosIndexes;
277277

278+
void setRegUnitState(MCRegUnit Unit, unsigned NewState);
279+
unsigned getRegUnitState(MCRegUnit Unit) const;
280+
278281
void setPhysRegState(MCRegister PhysReg, unsigned NewState);
279282
bool isPhysRegFree(MCRegister PhysReg) const;
280283

@@ -448,14 +451,22 @@ bool RegAllocFastImpl::shouldAllocateRegister(const Register Reg) const {
448451
return ShouldAllocateRegisterImpl(*TRI, *MRI, Reg);
449452
}
450453

454+
void RegAllocFastImpl::setRegUnitState(MCRegUnit Unit, unsigned NewState) {
455+
RegUnitStates[static_cast<unsigned>(Unit)] = NewState;
456+
}
457+
458+
unsigned RegAllocFastImpl::getRegUnitState(MCRegUnit Unit) const {
459+
return RegUnitStates[static_cast<unsigned>(Unit)];
460+
}
461+
451462
void RegAllocFastImpl::setPhysRegState(MCRegister PhysReg, unsigned NewState) {
452463
for (MCRegUnit Unit : TRI->regunits(PhysReg))
453-
RegUnitStates[Unit] = NewState;
464+
setRegUnitState(Unit, NewState);
454465
}
455466

456467
bool RegAllocFastImpl::isPhysRegFree(MCRegister PhysReg) const {
457468
for (MCRegUnit Unit : TRI->regunits(PhysReg)) {
458-
if (RegUnitStates[Unit] != regFree)
469+
if (getRegUnitState(Unit) != regFree)
459470
return false;
460471
}
461472
return true;
@@ -709,7 +720,7 @@ void RegAllocFastImpl::reloadAtBegin(MachineBasicBlock &MBB) {
709720
continue;
710721

711722
MCRegUnit FirstUnit = *TRI->regunits(PhysReg).begin();
712-
if (RegUnitStates[FirstUnit] == regLiveIn)
723+
if (getRegUnitState(FirstUnit) == regLiveIn)
713724
continue;
714725

715726
assert((&MBB != &MBB.getParent()->front() || IgnoreMissingDefs) &&
@@ -750,7 +761,7 @@ bool RegAllocFastImpl::displacePhysReg(MachineInstr &MI, MCRegister PhysReg) {
750761
bool displacedAny = false;
751762

752763
for (MCRegUnit Unit : TRI->regunits(PhysReg)) {
753-
switch (unsigned VirtReg = RegUnitStates[Unit]) {
764+
switch (unsigned VirtReg = getRegUnitState(Unit)) {
754765
default: {
755766
LiveRegMap::iterator LRI = findLiveVirtReg(VirtReg);
756767
assert(LRI != LiveVirtRegs.end() && "datastructures in sync");
@@ -767,7 +778,7 @@ bool RegAllocFastImpl::displacePhysReg(MachineInstr &MI, MCRegister PhysReg) {
767778
break;
768779
}
769780
case regPreAssigned:
770-
RegUnitStates[Unit] = regFree;
781+
setRegUnitState(Unit, regFree);
771782
displacedAny = true;
772783
break;
773784
case regFree:
@@ -781,7 +792,7 @@ void RegAllocFastImpl::freePhysReg(MCRegister PhysReg) {
781792
LLVM_DEBUG(dbgs() << "Freeing " << printReg(PhysReg, TRI) << ':');
782793

783794
MCRegUnit FirstUnit = *TRI->regunits(PhysReg).begin();
784-
switch (unsigned VirtReg = RegUnitStates[FirstUnit]) {
795+
switch (unsigned VirtReg = getRegUnitState(FirstUnit)) {
785796
case regFree:
786797
LLVM_DEBUG(dbgs() << '\n');
787798
return;
@@ -806,7 +817,7 @@ void RegAllocFastImpl::freePhysReg(MCRegister PhysReg) {
806817
/// \returns spillImpossible when PhysReg or an alias can't be spilled.
807818
unsigned RegAllocFastImpl::calcSpillCost(MCPhysReg PhysReg) const {
808819
for (MCRegUnit Unit : TRI->regunits(PhysReg)) {
809-
switch (unsigned VirtReg = RegUnitStates[Unit]) {
820+
switch (unsigned VirtReg = getRegUnitState(Unit)) {
810821
case regFree:
811822
break;
812823
case regPreAssigned:
@@ -1292,7 +1303,7 @@ bool RegAllocFastImpl::setPhysReg(MachineInstr &MI, MachineOperand &MO,
12921303

12931304
void RegAllocFastImpl::dumpState() const {
12941305
for (MCRegUnit Unit : TRI->regunits()) {
1295-
switch (unsigned VirtReg = RegUnitStates[Unit]) {
1306+
switch (unsigned VirtReg = getRegUnitState(Unit)) {
12961307
case regFree:
12971308
break;
12981309
case regPreAssigned:
@@ -1326,7 +1337,7 @@ void RegAllocFastImpl::dumpState() const {
13261337
if (PhysReg != 0) {
13271338
assert(Register::isPhysicalRegister(PhysReg) && "mapped to physreg");
13281339
for (MCRegUnit Unit : TRI->regunits(PhysReg)) {
1329-
assert(RegUnitStates[Unit] == VirtReg && "inverse map valid");
1340+
assert(getRegUnitState(Unit) == VirtReg && "inverse map valid");
13301341
}
13311342
}
13321343
}

0 commit comments

Comments
 (0)