Skip to content

[CodeGen] Use non-static Register::virtRegIndex() instead of static Register::virtReg2Index. NFC #125031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/RegisterPressure.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ class LiveRegSet {

unsigned getSparseIndexFromReg(Register Reg) const {
if (Reg.isVirtual())
return Register::virtReg2Index(Reg) + NumRegUnits;
return Reg.virtRegIndex() + NumRegUnits;
assert(Reg < NumRegUnits);
return Reg;
}
Expand Down
4 changes: 1 addition & 3 deletions llvm/include/llvm/CodeGen/TargetRegisterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1383,9 +1383,7 @@ class BitMaskClassIterator {
// This is useful when building IndexedMaps keyed on virtual registers
struct VirtReg2IndexFunctor {
using argument_type = Register;
unsigned operator()(Register Reg) const {
return Register::virtReg2Index(Reg);
}
unsigned operator()(Register Reg) const { return Reg.virtRegIndex(); }
};

/// Prints virtual and physical registers with or without a TRI instance.
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/CodeGen/DetectDeadLanes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void DeadLaneDetector::addUsedLanesOnOperand(const MachineOperand &MO,
UsedLanes = TRI->composeSubRegIndexLaneMask(MOSubReg, UsedLanes);
UsedLanes &= MRI->getMaxLaneMaskForVReg(MOReg);

unsigned MORegIdx = Register::virtReg2Index(MOReg);
unsigned MORegIdx = MOReg.virtRegIndex();
DeadLaneDetector::VRegInfo &MORegInfo = VRegInfos[MORegIdx];
LaneBitmask PrevUsedLanes = MORegInfo.UsedLanes;
// Any change at all?
Expand Down Expand Up @@ -147,7 +147,7 @@ DeadLaneDetector::transferUsedLanes(const MachineInstr &MI,
const MachineOperand &MO) const {
unsigned OpNum = MO.getOperandNo();
assert(lowersToCopies(MI) &&
DefinedByCopy[Register::virtReg2Index(MI.getOperand(0).getReg())]);
DefinedByCopy[MI.getOperand(0).getReg().virtRegIndex()]);

switch (MI.getOpcode()) {
case TargetOpcode::COPY:
Expand Down Expand Up @@ -204,7 +204,7 @@ void DeadLaneDetector::transferDefinedLanesStep(const MachineOperand &Use,
Register DefReg = Def.getReg();
if (!DefReg.isVirtual())
return;
unsigned DefRegIdx = Register::virtReg2Index(DefReg);
unsigned DefRegIdx = DefReg.virtRegIndex();
if (!DefinedByCopy.test(DefRegIdx))
return;

Expand Down Expand Up @@ -433,7 +433,7 @@ bool DetectDeadLanes::isUndefInput(const DeadLaneDetector &DLD,
Register DefReg = Def.getReg();
if (!DefReg.isVirtual())
return false;
unsigned DefRegIdx = Register::virtReg2Index(DefReg);
unsigned DefRegIdx = DefReg.virtRegIndex();
if (!DLD.isDefinedByCopy(DefRegIdx))
return false;

Expand Down Expand Up @@ -506,7 +506,7 @@ DetectDeadLanes::modifySubRegisterOperandStatus(const DeadLaneDetector &DLD,
Register Reg = MO.getReg();
if (!Reg.isVirtual())
continue;
unsigned RegIdx = Register::virtReg2Index(Reg);
unsigned RegIdx = Reg.virtRegIndex();
const DeadLaneDetector::VRegInfo &RegInfo = DLD.getVRegInfo(RegIdx);
if (MO.isDef() && !MO.isDead() && RegInfo.UsedLanes.none()) {
LLVM_DEBUG(dbgs()
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/CodeGen/InitUndef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ bool InitUndef::handleSubReg(MachineFunction &MF, MachineInstr &MI,
Register Reg = UseMO.getReg();
if (NewRegs.count(Reg))
continue;
DeadLaneDetector::VRegInfo Info =
DLD.getVRegInfo(Register::virtReg2Index(Reg));
DeadLaneDetector::VRegInfo Info = DLD.getVRegInfo(Reg.virtRegIndex());

if (Info.UsedLanes == Info.DefinedLanes)
continue;
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/MachineVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3178,7 +3178,7 @@ struct VRegFilter {
for (Register Reg : FromRegSet) {
if (!Reg.isVirtual())
continue;
unsigned Index = Register::virtReg2Index(Reg);
unsigned Index = Reg.virtRegIndex();
if (Index < SparseUniverseMax) {
if (Index < SparseUniverse && Sparse.test(Index))
continue;
Expand All @@ -3201,7 +3201,7 @@ struct VRegFilter {
Dense.reserve(NewDenseSize);
for (unsigned I = Begin; I < End; ++I) {
Register Reg = ToVRegs[I];
unsigned Index = Register::virtReg2Index(Reg);
unsigned Index = Reg.virtRegIndex();
if (Index < SparseUniverseMax)
Sparse.set(Index);
else
Expand Down
22 changes: 10 additions & 12 deletions llvm/lib/CodeGen/RegAllocFast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,7 @@ class RegAllocFastImpl {

explicit LiveReg(Register VirtReg) : VirtReg(VirtReg) {}

unsigned getSparseSetIndex() const {
return Register::virtReg2Index(VirtReg);
}
unsigned getSparseSetIndex() const { return VirtReg.virtRegIndex(); }
};

using LiveRegMap = SparseSet<LiveReg, identity<unsigned>, uint16_t>;
Expand Down Expand Up @@ -349,11 +347,11 @@ class RegAllocFastImpl {
unsigned calcSpillCost(MCPhysReg PhysReg) const;

LiveRegMap::iterator findLiveVirtReg(Register VirtReg) {
return LiveVirtRegs.find(Register::virtReg2Index(VirtReg));
return LiveVirtRegs.find(VirtReg.virtRegIndex());
}

LiveRegMap::const_iterator findLiveVirtReg(Register VirtReg) const {
return LiveVirtRegs.find(Register::virtReg2Index(VirtReg));
return LiveVirtRegs.find(VirtReg.virtRegIndex());
}

void assignVirtToPhysReg(MachineInstr &MI, LiveReg &, MCPhysReg PhysReg);
Expand Down Expand Up @@ -493,7 +491,7 @@ static bool dominates(InstrPosIndexes &PosIndexes, const MachineInstr &A,

/// Returns false if \p VirtReg is known to not live out of the current block.
bool RegAllocFastImpl::mayLiveOut(Register VirtReg) {
if (MayLiveAcrossBlocks.test(Register::virtReg2Index(VirtReg))) {
if (MayLiveAcrossBlocks.test(VirtReg.virtRegIndex())) {
// Cannot be live-out if there are no successors.
return !MBB->succ_empty();
}
Expand All @@ -506,15 +504,15 @@ bool RegAllocFastImpl::mayLiveOut(Register VirtReg) {
// Find the first def in the self loop MBB.
for (const MachineInstr &DefInst : MRI->def_instructions(VirtReg)) {
if (DefInst.getParent() != MBB) {
MayLiveAcrossBlocks.set(Register::virtReg2Index(VirtReg));
MayLiveAcrossBlocks.set(VirtReg.virtRegIndex());
return true;
} else {
if (!SelfLoopDef || dominates(PosIndexes, DefInst, *SelfLoopDef))
SelfLoopDef = &DefInst;
}
}
if (!SelfLoopDef) {
MayLiveAcrossBlocks.set(Register::virtReg2Index(VirtReg));
MayLiveAcrossBlocks.set(VirtReg.virtRegIndex());
return true;
}
}
Expand All @@ -525,7 +523,7 @@ bool RegAllocFastImpl::mayLiveOut(Register VirtReg) {
unsigned C = 0;
for (const MachineInstr &UseInst : MRI->use_nodbg_instructions(VirtReg)) {
if (UseInst.getParent() != MBB || ++C >= Limit) {
MayLiveAcrossBlocks.set(Register::virtReg2Index(VirtReg));
MayLiveAcrossBlocks.set(VirtReg.virtRegIndex());
// Cannot be live-out if there are no successors.
return !MBB->succ_empty();
}
Expand All @@ -535,7 +533,7 @@ bool RegAllocFastImpl::mayLiveOut(Register VirtReg) {
// value inside a self looping block.
if (SelfLoopDef == &UseInst ||
!dominates(PosIndexes, *SelfLoopDef, UseInst)) {
MayLiveAcrossBlocks.set(Register::virtReg2Index(VirtReg));
MayLiveAcrossBlocks.set(VirtReg.virtRegIndex());
return true;
}
}
Expand All @@ -546,15 +544,15 @@ bool RegAllocFastImpl::mayLiveOut(Register VirtReg) {

/// Returns false if \p VirtReg is known to not be live into the current block.
bool RegAllocFastImpl::mayLiveIn(Register VirtReg) {
if (MayLiveAcrossBlocks.test(Register::virtReg2Index(VirtReg)))
if (MayLiveAcrossBlocks.test(VirtReg.virtRegIndex()))
return !MBB->pred_empty();

// See if the first \p Limit def of the register are all in the current block.
static const unsigned Limit = 8;
unsigned C = 0;
for (const MachineInstr &DefInst : MRI->def_instructions(VirtReg)) {
if (DefInst.getParent() != MBB || ++C >= Limit) {
MayLiveAcrossBlocks.set(Register::virtReg2Index(VirtReg));
MayLiveAcrossBlocks.set(VirtReg.virtRegIndex());
return !MBB->pred_empty();
}
}
Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/CodeGen/RegisterScavenging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,7 @@ static bool scavengeFrameVirtualRegsInBlock(MachineRegisterInfo &MRI,
// We only care about virtual registers and ignore virtual registers
// created by the target callbacks in the process (those will be handled
// in a scavenging round).
if (!Reg.isVirtual() ||
Register::virtReg2Index(Reg) >= InitialNumVirtRegs)
if (!Reg.isVirtual() || Reg.virtRegIndex() >= InitialNumVirtRegs)
continue;
if (!MO.readsReg())
continue;
Expand All @@ -432,8 +431,7 @@ static bool scavengeFrameVirtualRegsInBlock(MachineRegisterInfo &MRI,
continue;
Register Reg = MO.getReg();
// Only vregs, no newly created vregs (see above).
if (!Reg.isVirtual() ||
Register::virtReg2Index(Reg) >= InitialNumVirtRegs)
if (!Reg.isVirtual() || Reg.virtRegIndex() >= InitialNumVirtRegs)
continue;
// We have to look at all operands anyway so we can precalculate here
// whether there is a reading operand. This allows use to skip the use
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ bool SelectionDAGISel::runOnMachineFunction(MachineFunction &mf) {
Def->getParent()->insert(std::next(InsertPos), MI);
} else
LLVM_DEBUG(dbgs() << "Dropping debug info for dead vreg"
<< Register::virtReg2Index(Reg) << "\n");
<< printReg(Reg) << '\n');
}

// Don't try and extend through copies in instruction referencing mode.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/TargetRegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Printable printReg(Register Reg, const TargetRegisterInfo *TRI,
if (Name != "") {
OS << '%' << Name;
} else {
OS << '%' << Register::virtReg2Index(Reg);
OS << '%' << Reg.virtRegIndex();
}
} else if (!TRI)
OS << '$' << "physreg" << Reg.id();
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Target/AArch64/AArch64StackTaggingPreRA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,8 @@ std::optional<int> AArch64StackTaggingPreRA::findFirstSlotCandidate() {
WorkList.push_back(DstReg);
continue;
}
LLVM_DEBUG(dbgs() << "[" << ST.FI << ":" << ST.Tag << "] use of %"
<< Register::virtReg2Index(UseReg) << " in " << UseI
<< "\n");
LLVM_DEBUG(dbgs() << "[" << ST.FI << ":" << ST.Tag << "] use of "
<< printReg(UseReg) << " in " << UseI << "\n");
Score++;
}
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/Hexagon/HexagonSplitDouble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ void HexagonSplitDoubleRegs::partitionRegisters(UUSetMap &P2Rs) {
}
if (MRI->getRegClass(T) != DoubleRC)
continue;
unsigned u = Register::virtReg2Index(T);
unsigned u = T.virtRegIndex();
if (FixedRegs[u])
continue;
LLVM_DEBUG(dbgs() << ' ' << printReg(T, TRI));
Expand Down
7 changes: 3 additions & 4 deletions llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,11 @@ struct PPCMIPeephole : public MachineFunctionPass {

#define addRegToUpdate(R) addRegToUpdateWithLine(R, __LINE__)
void PPCMIPeephole::addRegToUpdateWithLine(Register Reg, int Line) {
if (!Register::isVirtualRegister(Reg))
if (!Reg.isVirtual())
return;
if (RegsToUpdate.insert(Reg).second)
LLVM_DEBUG(dbgs() << "Adding register: " << Register::virtReg2Index(Reg)
<< " on line " << Line
<< " for re-computation of kill flags\n");
LLVM_DEBUG(dbgs() << "Adding register: " << printReg(Reg) << " on line "
<< Line << " for re-computation of kill flags\n");
}

// Initialize class variables.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/WebAssembly/WebAssemblyExplicitLocals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ bool WebAssemblyExplicitLocals::runOnMachineFunction(MachineFunction &MF) {
const TargetRegisterClass *RC = MRI.getRegClass(OldReg);
Register NewReg = MRI.createVirtualRegister(RC);
auto InsertPt = std::next(MI.getIterator());
if (UseEmpty[Register::virtReg2Index(OldReg)]) {
if (UseEmpty[OldReg.virtRegIndex()]) {
unsigned Opc = getDropOpcode(RC);
MachineInstr *Drop =
BuildMI(MBB, InsertPt, MI.getDebugLoc(), TII->get(Opc))
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/WebAssembly/WebAssemblyRegColoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ bool WebAssemblyRegColoring::runOnMachineFunction(MachineFunction &MF) {
// If we reassigned the stack pointer, update the debug frame base info.
if (Old != New && MFI.isFrameBaseVirtual() && MFI.getFrameBaseVreg() == Old)
MFI.setFrameBaseVreg(New);
LLVM_DEBUG(dbgs() << "Assigning vreg" << Register::virtReg2Index(LI->reg())
<< " to vreg" << Register::virtReg2Index(New) << "\n");
LLVM_DEBUG(dbgs() << "Assigning vreg " << printReg(LI->reg()) << " to vreg "
<< printReg(New) << "\n");
}
if (!Changed)
return false;
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Target/X86/X86FastPreTileConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ int X86FastPreTileConfig::getStackSpaceFor(Register VirtReg) {
/// If \p VirtReg live out of the current MBB, it must live out of the current
/// config
bool X86FastPreTileConfig::mayLiveOut(Register VirtReg, MachineInstr *CfgMI) {
if (MayLiveAcrossBlocks.test(Register::virtReg2Index(VirtReg)))
if (MayLiveAcrossBlocks.test(VirtReg.virtRegIndex()))
return true;

for (const MachineInstr &UseInst : MRI->use_nodbg_instructions(VirtReg)) {
if (UseInst.getParent() != MBB) {
MayLiveAcrossBlocks.set(Register::virtReg2Index(VirtReg));
MayLiveAcrossBlocks.set(VirtReg.virtRegIndex());
return true;
}

Expand All @@ -150,7 +150,7 @@ bool X86FastPreTileConfig::mayLiveOut(Register VirtReg, MachineInstr *CfgMI) {
// tile register.
if (CfgMI) {
if (dominates(*MBB, *CfgMI, UseInst)) {
MayLiveAcrossBlocks.set(Register::virtReg2Index(VirtReg));
MayLiveAcrossBlocks.set(VirtReg.virtRegIndex());
return true;
}
}
Expand Down Expand Up @@ -355,7 +355,7 @@ void X86FastPreTileConfig::convertPHI(MachineBasicBlock *MBB,
// Mark it as liveout, so that it will be spilled when visit
// the incoming MBB. Otherwise since phi will be deleted, it
// would miss spill when visit incoming MBB.
MayLiveAcrossBlocks.set(Register::virtReg2Index(InTileReg));
MayLiveAcrossBlocks.set(InTileReg.virtRegIndex());
MachineBasicBlock *InMBB = PHI.getOperand(I + 1).getMBB();

MachineInstr *TileDefMI = MRI->getVRegDef(InTileReg);
Expand Down