Skip to content

Commit

Permalink
[CodeGen] Remove uses of Register::isPhysicalRegister/isVirtualRegist…
Browse files Browse the repository at this point in the history
…er. NFC

Use isPhysical/isVirtual methods.

Reviewed By: foad

Differential Revision: https://reviews.llvm.org/D141715
  • Loading branch information
topperc committed Jan 13, 2023
1 parent 2ca4b4f commit e72ca52
Show file tree
Hide file tree
Showing 66 changed files with 267 additions and 309 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ void llvm::calculateDbgEntityHistory(const MachineFunction *MF,
continue;
// If this is a virtual register, only clobber it since it doesn't
// have aliases.
if (Register::isVirtualRegister(MO.getReg()))
if (MO.getReg().isVirtual())
clobberRegisterUses(RegVars, MO.getReg(), DbgValues, LiveEntries,
MI);
// If this is a register def operand, it may end a debug value
Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,7 @@ static void interpretValues(const MachineInstr *CurMI,
return;

for (const MachineOperand &MO : MI.operands()) {
if (MO.isReg() && MO.isDef() &&
Register::isPhysicalRegister(MO.getReg())) {
if (MO.isReg() && MO.isDef() && MO.getReg().isPhysical()) {
for (auto &FwdReg : ForwardedRegWorklist)
if (TRI.regsOverlap(FwdReg.first, MO.getReg()))
Defs.insert(FwdReg.first);
Expand Down Expand Up @@ -929,8 +928,7 @@ void DwarfDebug::constructCallSiteEntryDIEs(const DISubprogram &SP,
// the callee.
const MachineOperand &CalleeOp = TII->getCalleeOperand(MI);
if (!CalleeOp.isGlobal() &&
(!CalleeOp.isReg() ||
!Register::isPhysicalRegister(CalleeOp.getReg())))
(!CalleeOp.isReg() || !CalleeOp.getReg().isPhysical()))
continue;

unsigned CallReg = 0;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void DwarfExpression::addAnd(unsigned Mask) {
bool DwarfExpression::addMachineReg(const TargetRegisterInfo &TRI,
llvm::Register MachineReg,
unsigned MaxSize) {
if (!llvm::Register::isPhysicalRegister(MachineReg)) {
if (!MachineReg.isPhysical()) {
if (isFrameRegister(TRI, MachineReg)) {
DwarfRegs.push_back(Register::createRegister(-1, nullptr));
return true;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/BranchFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1875,7 +1875,7 @@ MachineBasicBlock::iterator findHoistingInsertPosAndDeps(MachineBasicBlock *MBB,
addRegAndItsAliases(Reg, TRI, Uses);
} else {
if (Uses.erase(Reg)) {
if (Register::isPhysicalRegister(Reg)) {
if (Reg.isPhysical()) {
for (MCSubRegIterator SubRegs(Reg, TRI); SubRegs.isValid(); ++SubRegs)
Uses.erase(*SubRegs); // Use sub-registers to be conservative
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/CalcSpillWeights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Register VirtRegAuxInfo::copyHint(const MachineInstr *MI, unsigned Reg,
if (!HReg)
return 0;

if (Register::isVirtualRegister(HReg))
if (HReg.isVirtual())
return Sub == HSub ? HReg : Register();

const TargetRegisterClass *RC = MRI.getRegClass(Reg);
Expand Down Expand Up @@ -107,7 +107,7 @@ bool VirtRegAuxInfo::isRematerializable(const LiveInterval &LI,

// If the original (pre-splitting) registers match this
// copy came from a split.
if (!Register::isVirtualRegister(Reg) || VRM.getOriginal(Reg) != Original)
if (!Reg.isVirtual() || VRM.getOriginal(Reg) != Original)
return false;

// Follow the copy live-in value.
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/CodeGenCommonISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ static bool MIIsInTerminatorSequence(const MachineInstr &MI) {

// Make sure that the copy dest is not a vreg when the copy source is a
// physical register.
if (!OPI2->isReg() || (!Register::isPhysicalRegister(OPI->getReg()) &&
Register::isPhysicalRegister(OPI2->getReg())))
if (!OPI2->isReg() ||
(!OPI->getReg().isPhysical() && OPI2->getReg().isPhysical()))
return false;

return true;
Expand Down
18 changes: 9 additions & 9 deletions llvm/lib/CodeGen/DetectDeadLanes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void DetectDeadLanes::addUsedLanesOnOperand(const MachineOperand &MO,
if (!MO.readsReg())
return;
Register MOReg = MO.getReg();
if (!Register::isVirtualRegister(MOReg))
if (!MOReg.isVirtual())
return;

unsigned MOSubReg = MO.getSubReg();
Expand All @@ -213,7 +213,7 @@ void DetectDeadLanes::addUsedLanesOnOperand(const MachineOperand &MO,
void DetectDeadLanes::transferUsedLanesStep(const MachineInstr &MI,
LaneBitmask UsedLanes) {
for (const MachineOperand &MO : MI.uses()) {
if (!MO.isReg() || !Register::isVirtualRegister(MO.getReg()))
if (!MO.isReg() || !MO.getReg().isVirtual())
continue;
LaneBitmask UsedOnMO = transferUsedLanes(MI, UsedLanes, MO);
addUsedLanesOnOperand(MO, UsedOnMO);
Expand Down Expand Up @@ -280,7 +280,7 @@ void DetectDeadLanes::transferDefinedLanesStep(const MachineOperand &Use,
return;
const MachineOperand &Def = *MI.defs().begin();
Register DefReg = Def.getReg();
if (!Register::isVirtualRegister(DefReg))
if (!DefReg.isVirtual())
return;
unsigned DefRegIdx = Register::virtReg2Index(DefReg);
if (!DefinedByCopy.test(DefRegIdx))
Expand Down Expand Up @@ -376,12 +376,12 @@ LaneBitmask DetectDeadLanes::determineInitialDefinedLanes(unsigned Reg) {
continue;

LaneBitmask MODefinedLanes;
if (Register::isPhysicalRegister(MOReg)) {
if (MOReg.isPhysical()) {
MODefinedLanes = LaneBitmask::getAll();
} else if (isCrossCopy(*MRI, DefMI, DefRC, MO)) {
MODefinedLanes = LaneBitmask::getAll();
} else {
assert(Register::isVirtualRegister(MOReg));
assert(MOReg.isVirtual());
if (MRI->hasOneDef(MOReg)) {
const MachineOperand &MODef = *MRI->def_begin(MOReg);
const MachineInstr &MODefMI = *MODef.getParent();
Expand Down Expand Up @@ -425,7 +425,7 @@ LaneBitmask DetectDeadLanes::determineInitialUsedLanes(unsigned Reg) {
Register DefReg = Def.getReg();
// The used lanes of COPY-like instruction operands are determined by the
// following dataflow analysis.
if (Register::isVirtualRegister(DefReg)) {
if (DefReg.isVirtual()) {
// But ignore copies across incompatible register classes.
bool CrossCopy = false;
if (lowersToCopies(UseMI)) {
Expand Down Expand Up @@ -465,7 +465,7 @@ bool DetectDeadLanes::isUndefInput(const MachineOperand &MO,
return false;
const MachineOperand &Def = MI.getOperand(0);
Register DefReg = Def.getReg();
if (!Register::isVirtualRegister(DefReg))
if (!DefReg.isVirtual())
return false;
unsigned DefRegIdx = Register::virtReg2Index(DefReg);
if (!DefinedByCopy.test(DefRegIdx))
Expand All @@ -477,7 +477,7 @@ bool DetectDeadLanes::isUndefInput(const MachineOperand &MO,
return false;

Register MOReg = MO.getReg();
if (Register::isVirtualRegister(MOReg)) {
if (MOReg.isVirtual()) {
const TargetRegisterClass *DstRC = MRI->getRegClass(DefReg);
*CrossCopy = isCrossCopy(*MRI, MI, DstRC, MO);
}
Expand Down Expand Up @@ -534,7 +534,7 @@ std::pair<bool, bool> DetectDeadLanes::runOnce(MachineFunction &MF) {
if (!MO.isReg())
continue;
Register Reg = MO.getReg();
if (!Register::isVirtualRegister(Reg))
if (!Reg.isVirtual())
continue;
unsigned RegIdx = Register::virtReg2Index(Reg);
const VRegInfo &RegInfo = VRegInfos[RegIdx];
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/CodeGen/EarlyIfConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,12 @@ bool SSAIfConv::InstrDependenciesAllowIfConv(MachineInstr *I) {
Register Reg = MO.getReg();

// Remember clobbered regunits.
if (MO.isDef() && Register::isPhysicalRegister(Reg))
if (MO.isDef() && Reg.isPhysical())
for (MCRegUnitIterator Units(Reg.asMCReg(), TRI); Units.isValid();
++Units)
ClobberedRegUnits.set(*Units);

if (!MO.readsReg() || !Register::isVirtualRegister(Reg))
if (!MO.readsReg() || !Reg.isVirtual())
continue;
MachineInstr *DefMI = MRI->getVRegDef(Reg);
if (!DefMI || DefMI->getParent() != Head)
Expand Down Expand Up @@ -387,7 +387,7 @@ bool SSAIfConv::findInsertionPoint() {
if (!MO.isReg())
continue;
Register Reg = MO.getReg();
if (!Register::isPhysicalRegister(Reg))
if (!Reg.isPhysical())
continue;
// I clobbers Reg, so it isn't live before I.
if (MO.isDef())
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/ExpandPostRAPseudos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ bool ExpandPostRA::LowerSubregToReg(MachineInstr *MI) {
assert(SubIdx != 0 && "Invalid index for insert_subreg");
Register DstSubReg = TRI->getSubReg(DstReg, SubIdx);

assert(Register::isPhysicalRegister(DstReg) &&
assert(DstReg.isPhysical() &&
"Insert destination must be in a physical register");
assert(Register::isPhysicalRegister(InsReg) &&
assert(InsReg.isPhysical() &&
"Inserted value must be in a physical register");

LLVM_DEBUG(dbgs() << "subreg: CONVERTING: " << *MI);
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ bool InstructionSelect::runOnMachineFunction(MachineFunction &MF) {
continue;
Register SrcReg = MI.getOperand(1).getReg();
Register DstReg = MI.getOperand(0).getReg();
if (Register::isVirtualRegister(SrcReg) &&
Register::isVirtualRegister(DstReg)) {
if (SrcReg.isVirtual() && DstReg.isVirtual()) {
auto SrcRC = MRI.getRegClass(SrcReg);
auto DstRC = MRI.getRegClass(DstReg);
if (SrcRC == DstRC) {
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ bool RegBankSelect::repairReg(
if (MO.isDef())
std::swap(Src, Dst);

assert((RepairPt.getNumInsertPoints() == 1 ||
Register::isPhysicalRegister(Dst)) &&
assert((RepairPt.getNumInsertPoints() == 1 || Dst.isPhysical()) &&
"We are about to create several defs for Dst");

// Build the instruction used to repair, then clone it at the right
Expand Down Expand Up @@ -398,7 +397,7 @@ void RegBankSelect::tryAvoidingSplit(

// Check if this is a physical or virtual register.
Register Reg = MO.getReg();
if (Register::isPhysicalRegister(Reg)) {
if (Reg.isPhysical()) {
// We are going to split every outgoing edges.
// Check that this is possible.
// FIXME: The machine representation is currently broken
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/CodeGen/GlobalISel/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Register llvm::constrainOperandRegClass(
const TargetRegisterClass &RegClass, MachineOperand &RegMO) {
Register Reg = RegMO.getReg();
// Assume physical registers are properly constrained.
assert(Register::isVirtualRegister(Reg) && "PhysReg not implemented");
assert(Reg.isVirtual() && "PhysReg not implemented");

// Save the old register class to check whether
// the change notifications will be required.
Expand Down Expand Up @@ -109,7 +109,7 @@ Register llvm::constrainOperandRegClass(
MachineOperand &RegMO, unsigned OpIdx) {
Register Reg = RegMO.getReg();
// Assume physical registers are properly constrained.
assert(Register::isVirtualRegister(Reg) && "PhysReg not implemented");
assert(Reg.isVirtual() && "PhysReg not implemented");

const TargetRegisterClass *OpRC = TII.getRegClass(II, OpIdx, &TRI, MF);
// Some of the target independent instructions, like COPY, may not impose any
Expand Down Expand Up @@ -171,7 +171,7 @@ bool llvm::constrainSelectedInstRegOperands(MachineInstr &I,

Register Reg = MO.getReg();
// Physical registers don't need to be constrained.
if (Register::isPhysicalRegister(Reg))
if (Reg.isPhysical())
continue;

// Register operands with a value of 0 (e.g. predicate operands) don't need
Expand Down Expand Up @@ -235,7 +235,7 @@ bool llvm::isTriviallyDead(const MachineInstr &MI,
continue;

Register Reg = MO.getReg();
if (Register::isPhysicalRegister(Reg) || !MRI.use_nodbg_empty(Reg))
if (Reg.isPhysical() || !MRI.use_nodbg_empty(Reg))
return false;
}
return true;
Expand Down Expand Up @@ -333,7 +333,7 @@ std::optional<ValueAndVReg> getConstantVRegValWithLookThrough(
break;
case TargetOpcode::COPY:
VReg = MI->getOperand(1).getReg();
if (Register::isPhysicalRegister(VReg))
if (VReg.isPhysical())
return std::nullopt;
break;
case TargetOpcode::G_INTTOPTR:
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/InlineSpiller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ static Register isFullCopyOf(const MachineInstr &MI, Register Reg) {

static void getVDefInterval(const MachineInstr &MI, LiveIntervals &LIS) {
for (const MachineOperand &MO : MI.operands())
if (MO.isReg() && MO.isDef() && Register::isVirtualRegister(MO.getReg()))
if (MO.isReg() && MO.isDef() && MO.getReg().isVirtual())
LIS.getInterval(MO.getReg());
}

Expand Down Expand Up @@ -911,7 +911,7 @@ foldMemoryOperand(ArrayRef<std::pair<MachineInstr *, unsigned>> Ops,
if (!MO->isReg())
continue;
Register Reg = MO->getReg();
if (!Reg || Register::isVirtualRegister(Reg) || MRI.isReserved(Reg)) {
if (!Reg || Reg.isVirtual() || MRI.isReserved(Reg)) {
continue;
}
// Skip non-Defs, including undef uses and internal reads.
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1848,8 +1848,7 @@ void InstrRefBasedLDV::transferRegisterDef(MachineInstr &MI) {
SmallVector<const MachineOperand *, 4> RegMaskPtrs;
for (const MachineOperand &MO : MI.operands()) {
// Determine whether the operand is a register def.
if (MO.isReg() && MO.isDef() && MO.getReg() &&
Register::isPhysicalRegister(MO.getReg()) &&
if (MO.isReg() && MO.isDef() && MO.getReg() && MO.getReg().isPhysical() &&
!IgnoreSPAlias(MO.getReg())) {
// Remove ranges of all aliased registers.
for (MCRegAliasIterator RAI(MO.getReg(), TRI, true); RAI.isValid(); ++RAI)
Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1587,8 +1587,7 @@ void VarLocBasedLDV::transferRegisterDef(MachineInstr &MI,
SmallVector<const uint32_t *, 4> RegMasks;
for (const MachineOperand &MO : MI.operands()) {
// Determine whether the operand is a register def.
if (MO.isReg() && MO.isDef() && MO.getReg() &&
Register::isPhysicalRegister(MO.getReg()) &&
if (MO.isReg() && MO.isDef() && MO.getReg() && MO.getReg().isPhysical() &&
!(MI.isCall() && MO.getReg() == SP)) {
// Remove ranges of all aliased registers.
for (MCRegAliasIterator RAI(MO.getReg(), TRI, true); RAI.isValid(); ++RAI)
Expand Down Expand Up @@ -2162,8 +2161,7 @@ bool VarLocBasedLDV::isEntryValueCandidate(
static void collectRegDefs(const MachineInstr &MI, DefinedRegsSet &Regs,
const TargetRegisterInfo *TRI) {
for (const MachineOperand &MO : MI.operands()) {
if (MO.isReg() && MO.isDef() && MO.getReg() &&
Register::isPhysicalRegister(MO.getReg())) {
if (MO.isReg() && MO.isDef() && MO.getReg() && MO.getReg().isPhysical()) {
Regs.insert(MO.getReg());
for (MCRegAliasIterator AI(MO.getReg(), TRI, true); AI.isValid(); ++AI)
Regs.insert(*AI);
Expand Down
19 changes: 8 additions & 11 deletions llvm/lib/CodeGen/LiveDebugVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,8 +764,7 @@ void LDVImpl::print(raw_ostream &OS) {

void UserValue::mapVirtRegs(LDVImpl *LDV) {
for (unsigned i = 0, e = locations.size(); i != e; ++i)
if (locations[i].isReg() &&
Register::isVirtualRegister(locations[i].getReg()))
if (locations[i].isReg() && locations[i].getReg().isVirtual())
LDV->mapVirtReg(locations[i].getReg(), this);
}

Expand All @@ -786,7 +785,7 @@ LDVImpl::getUserValue(const DILocalVariable *Var,
}

void LDVImpl::mapVirtReg(Register VirtReg, UserValue *EC) {
assert(Register::isVirtualRegister(VirtReg) && "Only map VirtRegs");
assert(VirtReg.isVirtual() && "Only map VirtRegs");
UserValue *&Leader = virtRegToEqClass[VirtReg];
Leader = UserValue::merge(Leader, EC);
}
Expand Down Expand Up @@ -822,7 +821,7 @@ bool LDVImpl::handleDebugValue(MachineInstr &MI, SlotIndex Idx) {
// will be incorrect.
bool Discard = false;
for (const MachineOperand &Op : MI.debug_operands()) {
if (Op.isReg() && Register::isVirtualRegister(Op.getReg())) {
if (Op.isReg() && Op.getReg().isVirtual()) {
const Register Reg = Op.getReg();
if (!LIS->hasInterval(Reg)) {
// The DBG_VALUE is described by a virtual register that does not have a
Expand Down Expand Up @@ -1018,9 +1017,8 @@ void UserValue::addDefsFromCopies(
SmallVectorImpl<std::pair<SlotIndex, DbgVariableValue>> &NewDefs,
MachineRegisterInfo &MRI, LiveIntervals &LIS) {
// Don't track copies from physregs, there are too many uses.
if (any_of(LocIntervals, [](auto LocI) {
return !Register::isVirtualRegister(LocI.second->reg());
}))
if (any_of(LocIntervals,
[](auto LocI) { return !LocI.second->reg().isVirtual(); }))
return;

// Collect all the (vreg, valno) pairs that are copies of LI.
Expand All @@ -1041,7 +1039,7 @@ void UserValue::addDefsFromCopies(
// arguments, and the argument registers are always call clobbered. We are
// better off in the source register which could be a callee-saved
// register, or it could be spilled.
if (!Register::isVirtualRegister(DstReg))
if (!DstReg.isVirtual())
continue;

// Is the value extended to reach this copy? If not, another def may be
Expand Down Expand Up @@ -1120,7 +1118,7 @@ void UserValue::computeIntervals(MachineRegisterInfo &MRI,
bool ShouldExtendDef = false;
for (unsigned LocNo : DbgValue.loc_nos()) {
const MachineOperand &LocMO = locations[LocNo];
if (!LocMO.isReg() || !Register::isVirtualRegister(LocMO.getReg())) {
if (!LocMO.isReg() || !LocMO.getReg().isVirtual()) {
ShouldExtendDef |= !LocMO.isReg();
continue;
}
Expand Down Expand Up @@ -1528,8 +1526,7 @@ void UserValue::rewriteLocations(VirtRegMap &VRM, const MachineFunction &MF,
unsigned SpillOffset = 0;
MachineOperand Loc = locations[I];
// Only virtual registers are rewritten.
if (Loc.isReg() && Loc.getReg() &&
Register::isVirtualRegister(Loc.getReg())) {
if (Loc.isReg() && Loc.getReg() && Loc.getReg().isVirtual()) {
Register VirtReg = Loc.getReg();
if (VRM.isAssignedReg(VirtReg) &&
Register::isPhysicalRegister(VRM.getPhys(VirtReg))) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/LiveInterval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ void LiveInterval::computeSubRangeUndefs(SmallVectorImpl<SlotIndex> &Undefs,
LaneBitmask LaneMask,
const MachineRegisterInfo &MRI,
const SlotIndexes &Indexes) const {
assert(Register::isVirtualRegister(reg()));
assert(reg().isVirtual());
LaneBitmask VRegMask = MRI.getMaxLaneMaskForVReg(reg());
assert((VRegMask & LaneMask).any());
const TargetRegisterInfo &TRI = *MRI.getTargetRegisterInfo();
Expand Down
Loading

0 comments on commit e72ca52

Please sign in to comment.