Skip to content

Commit

Permalink
[MC] Use subregs/superregs instead of MCSubRegIterator/MCSuperRegIter…
Browse files Browse the repository at this point in the history
…ator. NFC.

Differential Revision: https://reviews.llvm.org/D148613
  • Loading branch information
jayfoad committed Apr 18, 2023
1 parent 83ae2d3 commit 14bc374
Show file tree
Hide file tree
Showing 39 changed files with 218 additions and 251 deletions.
5 changes: 2 additions & 3 deletions llvm/include/llvm/CodeGen/LivePhysRegs.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ class LivePhysRegs {
void addReg(MCPhysReg Reg) {
assert(TRI && "LivePhysRegs is not initialized.");
assert(Reg <= TRI->getNumRegs() && "Expected a physical register.");
for (MCSubRegIterator SubRegs(Reg, TRI, /*IncludeSelf=*/true);
SubRegs.isValid(); ++SubRegs)
LiveRegs.insert(*SubRegs);
for (MCPhysReg SubReg : TRI->subregs_inclusive(Reg))
LiveRegs.insert(SubReg);
}

/// Removes a physical register, all its sub-registers, and all its
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/MC/MCRegisterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,8 @@ class MCSuperRegIterator : public MCRegisterInfo::DiffListIterator {
// Definition for isSuperRegister. Put it down here since it needs the
// iterator defined above in addition to the MCRegisterInfo class itself.
inline bool MCRegisterInfo::isSuperRegister(MCRegister RegA, MCRegister RegB) const{
for (MCSuperRegIterator I(RegA, this); I.isValid(); ++I)
if (*I == RegB)
for (MCPhysReg I : superregs(RegA))
if (I == RegB)
return true;
return false;
}
Expand Down
8 changes: 3 additions & 5 deletions llvm/lib/CodeGen/AggressiveAntiDepBreaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,8 @@ void AggressiveAntiDepBreaker::GetPassthruRegs(
if ((MO.isDef() && MI.isRegTiedToUseOperand(i)) ||
IsImplicitDefUse(MI, MO)) {
const Register Reg = MO.getReg();
for (MCSubRegIterator SubRegs(Reg, TRI, /*IncludeSelf=*/true);
SubRegs.isValid(); ++SubRegs)
PassthruRegs.insert(*SubRegs);
for (MCPhysReg SubReg : TRI->subregs_inclusive(Reg))
PassthruRegs.insert(SubReg);
}
}
}
Expand Down Expand Up @@ -322,8 +321,7 @@ void AggressiveAntiDepBreaker::HandleLastUse(unsigned Reg, unsigned KillIdx,
// was not live because otherwise, regardless whether we have an explicit
// use of the subregister, the subregister's contents are needed for the
// uses of the superregister.
for (MCSubRegIterator SubRegs(Reg, TRI); SubRegs.isValid(); ++SubRegs) {
unsigned SubregReg = *SubRegs;
for (MCPhysReg SubregReg : TRI->subregs(Reg)) {
if (!State->IsLive(SubregReg)) {
KillIndices[SubregReg] = KillIdx;
DefIndices[SubregReg] = ~0u;
Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ bool DwarfExpression::addMachineReg(const TargetRegisterInfo &TRI,

// Walk up the super-register chain until we find a valid number.
// For example, EAX on x86_64 is a 32-bit fragment of RAX with offset 0.
for (MCSuperRegIterator SR(MachineReg, &TRI); SR.isValid(); ++SR) {
Reg = TRI.getDwarfRegNum(*SR, false);
for (MCPhysReg SR : TRI.superregs(MachineReg)) {
Reg = TRI.getDwarfRegNum(SR, false);
if (Reg >= 0) {
unsigned Idx = TRI.getSubRegIndex(*SR, MachineReg);
unsigned Idx = TRI.getSubRegIndex(SR, MachineReg);
unsigned Size = TRI.getSubRegIdxSize(Idx);
unsigned RegOffset = TRI.getSubRegIdxOffset(Idx);
DwarfRegs.push_back(Register::createRegister(Reg, "super-register"));
Expand All @@ -142,11 +142,11 @@ bool DwarfExpression::addMachineReg(const TargetRegisterInfo &TRI,
// this doesn't find a combination of subregisters that fully cover
// the register (even though one may exist).
SmallBitVector Coverage(RegSize, false);
for (MCSubRegIterator SR(MachineReg, &TRI); SR.isValid(); ++SR) {
unsigned Idx = TRI.getSubRegIndex(MachineReg, *SR);
for (MCPhysReg SR : TRI.subregs(MachineReg)) {
unsigned Idx = TRI.getSubRegIndex(MachineReg, SR);
unsigned Size = TRI.getSubRegIdxSize(Idx);
unsigned Offset = TRI.getSubRegIdxOffset(Idx);
Reg = TRI.getDwarfRegNum(*SR, false);
Reg = TRI.getDwarfRegNum(SR, false);
if (Reg < 0)
continue;

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/BranchFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1877,8 +1877,8 @@ MachineBasicBlock::iterator findHoistingInsertPosAndDeps(MachineBasicBlock *MBB,
} else {
if (Uses.erase(Reg)) {
if (Reg.isPhysical()) {
for (MCSubRegIterator SubRegs(Reg, TRI); SubRegs.isValid(); ++SubRegs)
Uses.erase(*SubRegs); // Use sub-registers to be conservative
for (MCPhysReg SubReg : TRI->subregs(Reg))
Uses.erase(SubReg); // Use sub-registers to be conservative
}
}
addRegAndItsAliases(Reg, TRI, Defs);
Expand Down
26 changes: 11 additions & 15 deletions llvm/lib/CodeGen/CriticalAntiDepBreaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,8 @@ void CriticalAntiDepBreaker::PrescanInstruction(MachineInstr &MI) {

if (MO.isUse() && Special) {
if (!KeepRegs.test(Reg)) {
for (MCSubRegIterator SubRegs(Reg, TRI, /*IncludeSelf=*/true);
SubRegs.isValid(); ++SubRegs)
KeepRegs.set(*SubRegs);
for (MCPhysReg SubReg : TRI->subregs_inclusive(Reg))
KeepRegs.set(SubReg);
}
}
}
Expand All @@ -238,13 +237,11 @@ void CriticalAntiDepBreaker::PrescanInstruction(MachineInstr &MI) {
// itself can't be changed.
if (MI.isRegTiedToUseOperand(I) &&
Classes[Reg] == reinterpret_cast<TargetRegisterClass *>(-1)) {
for (MCSubRegIterator SubRegs(Reg, TRI, /*IncludeSelf=*/true);
SubRegs.isValid(); ++SubRegs) {
KeepRegs.set(*SubRegs);
for (MCPhysReg SubReg : TRI->subregs_inclusive(Reg)) {
KeepRegs.set(SubReg);
}
for (MCSuperRegIterator SuperRegs(Reg, TRI);
SuperRegs.isValid(); ++SuperRegs) {
KeepRegs.set(*SuperRegs);
for (MCPhysReg SuperReg : TRI->superregs(Reg)) {
KeepRegs.set(SuperReg);
}
}
}
Expand All @@ -264,8 +261,8 @@ void CriticalAntiDepBreaker::ScanInstruction(MachineInstr &MI, unsigned Count) {

if (MO.isRegMask()) {
auto ClobbersPhysRegAndSubRegs = [&](unsigned PhysReg) {
for (MCSubRegIterator SRI(PhysReg, TRI, true); SRI.isValid(); ++SRI)
if (!MO.clobbersPhysReg(*SRI))
for (MCPhysReg SR : TRI->subregs_inclusive(PhysReg))
if (!MO.clobbersPhysReg(SR))
return false;

return true;
Expand Down Expand Up @@ -297,8 +294,7 @@ void CriticalAntiDepBreaker::ScanInstruction(MachineInstr &MI, unsigned Count) {

// For the reg itself and all subregs: update the def to current;
// reset the kill state, any restrictions, and references.
for (MCSubRegIterator SRI(Reg, TRI, true); SRI.isValid(); ++SRI) {
unsigned SubregReg = *SRI;
for (MCPhysReg SubregReg : TRI->subregs_inclusive(Reg)) {
DefIndices[SubregReg] = Count;
KillIndices[SubregReg] = ~0u;
Classes[SubregReg] = nullptr;
Expand All @@ -307,8 +303,8 @@ void CriticalAntiDepBreaker::ScanInstruction(MachineInstr &MI, unsigned Count) {
KeepRegs.reset(SubregReg);
}
// Conservatively mark super-registers as unusable.
for (MCSuperRegIterator SR(Reg, TRI); SR.isValid(); ++SR)
Classes[*SR] = reinterpret_cast<TargetRegisterClass *>(-1);
for (MCPhysReg SR : TRI->superregs(Reg))
Classes[SR] = reinterpret_cast<TargetRegisterClass *>(-1);
}
}
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
Expand Down
14 changes: 6 additions & 8 deletions llvm/lib/CodeGen/IfConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1516,8 +1516,8 @@ static void UpdatePredRedefs(MachineInstr &MI, LivePhysRegs &Redefs) {
MIB.addReg(Reg, RegState::Implicit);
else {
bool HasLiveSubReg = false;
for (MCSubRegIterator S(Reg, TRI); S.isValid(); ++S) {
if (!LiveBeforeMI.count(*S))
for (MCPhysReg S : TRI->subregs(Reg)) {
if (!LiveBeforeMI.count(S))
continue;
HasLiveSubReg = true;
break;
Expand Down Expand Up @@ -1958,17 +1958,15 @@ bool IfConverter::IfConvertDiamondCommon(
} else if (!RedefsByFalse.count(Reg)) {
// These are defined before ctrl flow reach the 'false' instructions.
// They cannot be modified by the 'true' instructions.
for (MCSubRegIterator SubRegs(Reg, TRI, /*IncludeSelf=*/true);
SubRegs.isValid(); ++SubRegs)
ExtUses.insert(*SubRegs);
for (MCPhysReg SubReg : TRI->subregs_inclusive(Reg))
ExtUses.insert(SubReg);
}
}

for (MCPhysReg Reg : Defs) {
if (!ExtUses.count(Reg)) {
for (MCSubRegIterator SubRegs(Reg, TRI, /*IncludeSelf=*/true);
SubRegs.isValid(); ++SubRegs)
RedefsByFalse.insert(*SubRegs);
for (MCPhysReg SubReg : TRI->subregs_inclusive(Reg))
RedefsByFalse.insert(SubReg);
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1544,12 +1544,12 @@ std::optional<ValueIDNum> InstrRefBasedLDV::getValueForInstrRef(
if (Size != MainRegSize || Offset) {
// Enumerate all subregisters, searching.
Register NewReg = 0;
for (MCSubRegIterator SRI(Reg, TRI, false); SRI.isValid(); ++SRI) {
unsigned Subreg = TRI->getSubRegIndex(Reg, *SRI);
for (MCPhysReg SR : TRI->subregs(Reg)) {
unsigned Subreg = TRI->getSubRegIndex(Reg, SR);
unsigned SubregSize = TRI->getSubRegIdxSize(Subreg);
unsigned SubregOffset = TRI->getSubRegIdxOffset(Subreg);
if (SubregSize == Size && SubregOffset == Offset) {
NewReg = *SRI;
NewReg = SR;
break;
}
}
Expand Down Expand Up @@ -2066,12 +2066,12 @@ bool InstrRefBasedLDV::transferSpillOrRestoreInst(MachineInstr &MI) {
};

// Then, transfer subreg bits.
for (MCSubRegIterator SRI(Reg, TRI, false); SRI.isValid(); ++SRI) {
for (MCPhysReg SR : TRI->subregs(Reg)) {
// Ensure this reg is tracked,
(void)MTracker->lookupOrTrackRegister(*SRI);
unsigned SubregIdx = TRI->getSubRegIndex(Reg, *SRI);
(void)MTracker->lookupOrTrackRegister(SR);
unsigned SubregIdx = TRI->getSubRegIndex(Reg, SR);
unsigned SpillID = MTracker->getLocID(Loc, SubregIdx);
DoTransfer(*SRI, SpillID);
DoTransfer(SR, SpillID);
}

// Directly lookup size of main source reg, and transfer.
Expand Down Expand Up @@ -2101,10 +2101,10 @@ bool InstrRefBasedLDV::transferSpillOrRestoreInst(MachineInstr &MI) {
MTracker->setReg(DestReg, ReadValue);
};

for (MCSubRegIterator SRI(Reg, TRI, false); SRI.isValid(); ++SRI) {
unsigned Subreg = TRI->getSubRegIndex(Reg, *SRI);
for (MCPhysReg SR : TRI->subregs(Reg)) {
unsigned Subreg = TRI->getSubRegIndex(Reg, SR);
unsigned SpillID = MTracker->getLocID(*Loc, Subreg);
DoTransfer(*SRI, SpillID);
DoTransfer(SR, SpillID);
}

// Directly look up this registers slot idx by size, and transfer.
Expand Down
8 changes: 2 additions & 6 deletions llvm/lib/CodeGen/LiveIntervals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,7 @@ void LiveIntervals::computeRegUnitRange(LiveRange &LR, unsigned Unit) {
bool IsReserved = false;
for (MCRegUnitRootIterator Root(Unit, TRI); Root.isValid(); ++Root) {
bool IsRootReserved = true;
for (MCSuperRegIterator Super(*Root, TRI, /*IncludeSelf=*/true);
Super.isValid(); ++Super) {
MCRegister Reg = *Super;
for (MCPhysReg Reg : TRI->superregs_inclusive(*Root)) {
if (!MRI->reg_empty(Reg))
LICalc->createDeadDefs(LR, Reg);
// A register unit is considered reserved if all its roots and all their
Expand All @@ -299,9 +297,7 @@ void LiveIntervals::computeRegUnitRange(LiveRange &LR, unsigned Unit) {
// Ignore uses of reserved registers. We only track defs of those.
if (!IsReserved) {
for (MCRegUnitRootIterator Root(Unit, TRI); Root.isValid(); ++Root) {
for (MCSuperRegIterator Super(*Root, TRI, /*IncludeSelf=*/true);
Super.isValid(); ++Super) {
MCRegister Reg = *Super;
for (MCPhysReg Reg : TRI->superregs_inclusive(*Root)) {
if (!MRI->reg_empty(Reg))
LICalc->extendToUses(LR, Reg);
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/LivePhysRegs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ void llvm::addLiveIns(MachineBasicBlock &MBB, const LivePhysRegs &LiveRegs) {
continue;
// Skip the register if we are about to add one of its super registers.
bool ContainsSuperReg = false;
for (MCSuperRegIterator SReg(Reg, &TRI); SReg.isValid(); ++SReg) {
if (LiveRegs.contains(*SReg) && !MRI.isReserved(*SReg)) {
for (MCPhysReg SReg : TRI.superregs(Reg)) {
if (LiveRegs.contains(SReg) && !MRI.isReserved(SReg)) {
ContainsSuperReg = true;
break;
}
Expand Down
Loading

0 comments on commit 14bc374

Please sign in to comment.