Skip to content

Commit a5b63b5

Browse files
authored
[VirtRegMap] Store MCRegister in Virt2PhysMap. (#108775)
Remove NO_PHYS_REG in favor of MCRegister() and converting MCRegister to bool.
1 parent 6749f2b commit a5b63b5

File tree

6 files changed

+17
-25
lines changed

6 files changed

+17
-25
lines changed

llvm/include/llvm/CodeGen/Register.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ class Register {
132132
/// Comparisons against register constants. E.g.
133133
/// * R == AArch64::WZR
134134
/// * R == 0
135-
/// * R == VirtRegMap::NO_PHYS_REG
136135
constexpr bool operator==(unsigned Other) const { return Reg == Other; }
137136
constexpr bool operator!=(unsigned Other) const { return Reg != Other; }
138137
constexpr bool operator==(int Other) const { return Reg == unsigned(Other); }

llvm/include/llvm/CodeGen/VirtRegMap.h

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class TargetInstrInfo;
3333
class VirtRegMap : public MachineFunctionPass {
3434
public:
3535
enum {
36-
NO_PHYS_REG = 0,
3736
NO_STACK_SLOT = (1L << 30)-1,
3837
MAX_STACK_SLOT = (1L << 18)-1
3938
};
@@ -49,7 +48,7 @@ class TargetInstrInfo;
4948
/// it; even spilled virtual registers (the register mapped to a
5049
/// spilled register is the temporary used to load it from the
5150
/// stack).
52-
IndexedMap<Register, VirtReg2IndexFunctor> Virt2PhysMap;
51+
IndexedMap<MCRegister, VirtReg2IndexFunctor> Virt2PhysMap;
5352

5453
/// Virt2StackSlotMap - This is virtual register to stack slot
5554
/// mapping. Each spilled virtual register has an entry in it
@@ -71,9 +70,7 @@ class TargetInstrInfo;
7170
public:
7271
static char ID;
7372

74-
VirtRegMap()
75-
: MachineFunctionPass(ID), Virt2PhysMap(NO_PHYS_REG),
76-
Virt2StackSlotMap(NO_STACK_SLOT) {}
73+
VirtRegMap() : MachineFunctionPass(ID), Virt2StackSlotMap(NO_STACK_SLOT) {}
7774
VirtRegMap(const VirtRegMap &) = delete;
7875
VirtRegMap &operator=(const VirtRegMap &) = delete;
7976

@@ -96,15 +93,13 @@ class TargetInstrInfo;
9693

9794
/// returns true if the specified virtual register is
9895
/// mapped to a physical register
99-
bool hasPhys(Register virtReg) const {
100-
return getPhys(virtReg) != NO_PHYS_REG;
101-
}
96+
bool hasPhys(Register virtReg) const { return getPhys(virtReg).isValid(); }
10297

10398
/// returns the physical register mapped to the specified
10499
/// virtual register
105100
MCRegister getPhys(Register virtReg) const {
106101
assert(virtReg.isVirtual());
107-
return MCRegister::from(Virt2PhysMap[virtReg]);
102+
return Virt2PhysMap[virtReg];
108103
}
109104

110105
/// creates a mapping for the specified virtual register to
@@ -130,9 +125,9 @@ class TargetInstrInfo;
130125
/// register mapping
131126
void clearVirt(Register virtReg) {
132127
assert(virtReg.isVirtual());
133-
assert(Virt2PhysMap[virtReg] != NO_PHYS_REG &&
128+
assert(Virt2PhysMap[virtReg] &&
134129
"attempt to clear a not assigned virtual register");
135-
Virt2PhysMap[virtReg] = NO_PHYS_REG;
130+
Virt2PhysMap[virtReg] = MCRegister();
136131
}
137132

138133
/// clears all virtual to physical register mappings
@@ -178,8 +173,7 @@ class TargetInstrInfo;
178173
return true;
179174
// Split register can be assigned a physical register as well as a
180175
// stack slot or remat id.
181-
return (Virt2SplitMap[virtReg] &&
182-
Virt2PhysMap[virtReg] != NO_PHYS_REG);
176+
return (Virt2SplitMap[virtReg] && Virt2PhysMap[virtReg]);
183177
}
184178

185179
/// returns the stack slot mapped to the specified virtual

llvm/include/llvm/MC/MCRegister.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ class MCRegister {
9191
/// Comparisons against register constants. E.g.
9292
/// * R == AArch64::WZR
9393
/// * R == 0
94-
/// * R == VirtRegMap::NO_PHYS_REG
9594
constexpr bool operator==(unsigned Other) const { return Reg == Other; }
9695
constexpr bool operator!=(unsigned Other) const { return Reg != Other; }
9796
constexpr bool operator==(int Other) const { return Reg == unsigned(Other); }

llvm/lib/CodeGen/VirtRegMap.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void VirtRegMap::grow() {
8484

8585
void VirtRegMap::assignVirt2Phys(Register virtReg, MCPhysReg physReg) {
8686
assert(virtReg.isVirtual() && Register::isPhysicalRegister(physReg));
87-
assert(Virt2PhysMap[virtReg] == NO_PHYS_REG &&
87+
assert(!Virt2PhysMap[virtReg] &&
8888
"attempt to assign physical register to already mapped "
8989
"virtual register");
9090
assert(!getRegInfo().isReserved(physReg) &&
@@ -146,7 +146,7 @@ void VirtRegMap::print(raw_ostream &OS, const Module*) const {
146146
OS << "********** REGISTER MAP **********\n";
147147
for (unsigned i = 0, e = MRI->getNumVirtRegs(); i != e; ++i) {
148148
Register Reg = Register::index2VirtReg(i);
149-
if (Virt2PhysMap[Reg] != (unsigned)VirtRegMap::NO_PHYS_REG) {
149+
if (Virt2PhysMap[Reg]) {
150150
OS << '[' << printReg(Reg, TRI) << " -> "
151151
<< printReg(Virt2PhysMap[Reg], TRI) << "] "
152152
<< TRI->getRegClassName(MRI->getRegClass(Reg)) << "\n";
@@ -347,8 +347,8 @@ void VirtRegRewriter::addMBBLiveIns() {
347347
continue;
348348
// This is a virtual register that is live across basic blocks. Its
349349
// assigned PhysReg must be marked as live-in to those blocks.
350-
Register PhysReg = VRM->getPhys(VirtReg);
351-
if (PhysReg == VirtRegMap::NO_PHYS_REG) {
350+
MCRegister PhysReg = VRM->getPhys(VirtReg);
351+
if (!PhysReg) {
352352
// There may be no physical register assigned if only some register
353353
// classes were already allocated.
354354
assert(!ClearVirtRegs && "Unmapped virtual register");
@@ -551,7 +551,7 @@ void VirtRegRewriter::rewrite() {
551551
continue;
552552
Register VirtReg = MO.getReg();
553553
MCRegister PhysReg = VRM->getPhys(VirtReg);
554-
if (PhysReg == VirtRegMap::NO_PHYS_REG)
554+
if (!PhysReg)
555555
continue;
556556

557557
assert(Register(PhysReg).isPhysical());

llvm/lib/Target/AMDGPU/SILowerWWMCopies.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,8 @@ void SILowerWWMCopies::addToWWMSpills(MachineFunction &MF, Register Reg) {
9090
if (Reg.isPhysical())
9191
return;
9292

93-
Register PhysReg = VRM->getPhys(Reg);
94-
assert(PhysReg != VirtRegMap::NO_PHYS_REG &&
95-
"should have allocated a physical register");
93+
MCRegister PhysReg = VRM->getPhys(Reg);
94+
assert(PhysReg && "should have allocated a physical register");
9695

9796
MFI->allocateWWMSpill(MF, PhysReg);
9897
}

llvm/lib/Target/X86/X86TileConfig.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,10 @@ bool X86TileConfig::runOnMachineFunction(MachineFunction &MF) {
128128
continue;
129129
if (MRI.getRegClass(VirtReg)->getID() != X86::TILERegClassID)
130130
continue;
131-
if (VRM.getPhys(VirtReg) == VirtRegMap::NO_PHYS_REG)
131+
MCRegister PhysReg = VRM.getPhys(VirtReg);
132+
if (!PhysReg)
132133
continue;
133-
unsigned Index = VRM.getPhys(VirtReg) - X86::TMM0;
134+
unsigned Index = PhysReg - X86::TMM0;
134135
if (!Phys2Virt[Index])
135136
Phys2Virt[Index] = VirtReg;
136137
}

0 commit comments

Comments
 (0)