Skip to content

Commit 77183a4

Browse files
authored
[CodeGen] Remove static member function Register::virtReg2Index. NFC (#127962)
Use the nonstatic member instead. I'm pretty sure the code in SPRIV is a layering violation. MC layer files are using a CodeGen header.
1 parent 2130b9c commit 77183a4

12 files changed

+21
-25
lines changed

llvm/include/llvm/CodeGen/Register.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,6 @@ class Register {
6060
return Reg & MCRegister::VirtualRegFlag;
6161
}
6262

63-
/// Convert a virtual register number to a 0-based index.
64-
/// The first virtual register in a function will get the index 0.
65-
static unsigned virtReg2Index(Register Reg) {
66-
assert(Reg.isVirtual() && "Not a virtual register");
67-
return Reg.id() & ~MCRegister::VirtualRegFlag;
68-
}
69-
7063
/// Convert a 0-based index to a virtual register number.
7164
/// This is the inverse operation of VirtReg2IndexFunctor below.
7265
static Register index2VirtReg(unsigned Index) {
@@ -84,7 +77,10 @@ class Register {
8477

8578
/// Convert a virtual register number to a 0-based index. The first virtual
8679
/// register in a function will get the index 0.
87-
unsigned virtRegIndex() const { return virtReg2Index(Reg); }
80+
unsigned virtRegIndex() const {
81+
assert(isVirtual() && "Not a virtual register");
82+
return Reg & ~MCRegister::VirtualRegFlag;
83+
}
8884

8985
/// Compute the frame index from a register value representing a stack slot.
9086
int stackSlotIndex() const {

llvm/include/llvm/CodeGen/ScheduleDAGInstrs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ namespace llvm {
5959
: VirtReg(VReg), LaneMask(LaneMask), SU(SU) {}
6060

6161
unsigned getSparseSetIndex() const {
62-
return Register::virtReg2Index(VirtReg);
62+
return Register(VirtReg).virtRegIndex();
6363
}
6464
};
6565

llvm/lib/CodeGen/DetectDeadLanes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ LaneBitmask DeadLaneDetector::determineInitialDefinedLanes(unsigned Reg) {
276276
if (lowersToCopies(DefMI)) {
277277
// Start optimisatically with no used or defined lanes for copy
278278
// instructions. The following dataflow analysis will add more bits.
279-
unsigned RegIdx = Register::virtReg2Index(Reg);
279+
unsigned RegIdx = Register(Reg).virtRegIndex();
280280
DefinedByCopy.set(RegIdx);
281281
PutInWorklist(RegIdx);
282282

llvm/lib/CodeGen/TargetRegisterInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ Printable printRegUnit(unsigned Unit, const TargetRegisterInfo *TRI) {
161161
Printable printVRegOrUnit(unsigned Unit, const TargetRegisterInfo *TRI) {
162162
return Printable([Unit, TRI](raw_ostream &OS) {
163163
if (Register::isVirtualRegister(Unit)) {
164-
OS << '%' << Register::virtReg2Index(Unit);
164+
OS << '%' << Register(Unit).virtRegIndex();
165165
} else {
166166
OS << printRegUnit(Unit, TRI);
167167
}

llvm/lib/Target/Hexagon/BitTracker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ namespace {
8484

8585
raw_ostream &operator<< (raw_ostream &OS, const printv &PV) {
8686
if (PV.R)
87-
OS << 'v' << Register::virtReg2Index(PV.R);
87+
OS << 'v' << Register(PV.R).virtRegIndex();
8888
else
8989
OS << 's';
9090
return OS;

llvm/lib/Target/Hexagon/HexagonBitSimplify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ namespace {
176176
}
177177

178178
static inline unsigned v2x(unsigned v) {
179-
return Register::virtReg2Index(v);
179+
return Register(v).virtRegIndex();
180180
}
181181

182182
static inline unsigned x2v(unsigned x) {

llvm/lib/Target/Hexagon/HexagonGenInsert.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ namespace {
167167
}
168168

169169
static inline unsigned v2x(unsigned v) {
170-
return Register::virtReg2Index(v);
170+
return Register(v).virtRegIndex();
171171
}
172172

173173
static inline unsigned x2v(unsigned x) {
@@ -271,7 +271,7 @@ namespace {
271271
CellMapShadow(const BitTracker &T) : BT(T) {}
272272

273273
const BitTracker::RegisterCell &lookup(unsigned VR) {
274-
unsigned RInd = Register::virtReg2Index(VR);
274+
unsigned RInd = Register(VR).virtRegIndex();
275275
// Grow the vector to at least 32 elements.
276276
if (RInd >= CVect.size())
277277
CVect.resize(std::max(RInd+16, 32U), nullptr);
@@ -1578,7 +1578,7 @@ bool HexagonGenInsert::runOnMachineFunction(MachineFunction &MF) {
15781578

15791579
IterListType Out;
15801580
for (IFMapType::iterator I = IFMap.begin(), E = IFMap.end(); I != E; ++I) {
1581-
unsigned Idx = Register::virtReg2Index(I->first);
1581+
unsigned Idx = Register(I->first).virtRegIndex();
15821582
if (Idx >= Cutoff)
15831583
Out.push_back(I);
15841584
}

llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVInstPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ void SPIRVInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
336336
if (OpNo < MI->getNumOperands()) {
337337
const MCOperand &Op = MI->getOperand(OpNo);
338338
if (Op.isReg())
339-
O << '%' << (Register::virtReg2Index(Op.getReg()) + 1);
339+
O << '%' << (Register(Op.getReg()).virtRegIndex() + 1);
340340
else if (Op.isImm())
341341
O << formatImm((int64_t)Op.getImm());
342342
else if (Op.isDFPImm())

llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVMCCodeEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static void emitOperand(const MCOperand &Op, SmallVectorImpl<char> &CB) {
7777
if (Op.isReg()) {
7878
// Emit the id index starting at 1 (0 is an invalid index).
7979
support::endian::write<uint32_t>(
80-
CB, Register::virtReg2Index(Op.getReg()) + 1, llvm::endianness::little);
80+
CB, Register(Op.getReg()).virtRegIndex() + 1, llvm::endianness::little);
8181
} else if (Op.isImm()) {
8282
support::endian::write(CB, static_cast<uint32_t>(Op.getImm()),
8383
llvm::endianness::little);

llvm/lib/Target/WebAssembly/WebAssemblyExplicitLocals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static void checkFrameBase(WebAssemblyFunctionInfo &MFI, unsigned Local,
6565
if (MFI.isFrameBaseVirtual() && Reg == MFI.getFrameBaseVreg()) {
6666
LLVM_DEBUG({
6767
dbgs() << "Allocating local " << Local << "for VReg "
68-
<< Register::virtReg2Index(Reg) << '\n';
68+
<< Register(Reg).virtRegIndex() << '\n';
6969
});
7070
MFI.setFrameBaseLocal(Local);
7171
}

0 commit comments

Comments
 (0)