[llvm] 14bc374 - [MC] Use subregs/superregs instead of MCSubRegIterator/MCSuperRegIterator. NFC.
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 18 05:29:50 PDT 2023
Author: Jay Foad
Date: 2023-04-18T13:29:41+01:00
New Revision: 14bc3748109c73adde7350da60366149ae0d4c3a
URL: https://github.com/llvm/llvm-project/commit/14bc3748109c73adde7350da60366149ae0d4c3a
DIFF: https://github.com/llvm/llvm-project/commit/14bc3748109c73adde7350da60366149ae0d4c3a.diff
LOG: [MC] Use subregs/superregs instead of MCSubRegIterator/MCSuperRegIterator. NFC.
Differential Revision: https://reviews.llvm.org/D148613
Added:
Modified:
llvm/include/llvm/CodeGen/LivePhysRegs.h
llvm/include/llvm/MC/MCRegisterInfo.h
llvm/lib/CodeGen/AggressiveAntiDepBreaker.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
llvm/lib/CodeGen/BranchFolding.cpp
llvm/lib/CodeGen/CriticalAntiDepBreaker.cpp
llvm/lib/CodeGen/IfConversion.cpp
llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
llvm/lib/CodeGen/LiveIntervals.cpp
llvm/lib/CodeGen/LivePhysRegs.cpp
llvm/lib/CodeGen/LiveVariables.cpp
llvm/lib/CodeGen/MachineFrameInfo.cpp
llvm/lib/CodeGen/MachineInstrBundle.cpp
llvm/lib/CodeGen/MachineRegisterInfo.cpp
llvm/lib/CodeGen/MachineSink.cpp
llvm/lib/CodeGen/RDFLiveness.cpp
llvm/lib/CodeGen/RDFRegisters.cpp
llvm/lib/CodeGen/RegUsageInfoCollector.cpp
llvm/lib/CodeGen/RegisterScavenging.cpp
llvm/lib/CodeGen/ScheduleDAGInstrs.cpp
llvm/lib/CodeGen/StackMaps.cpp
llvm/lib/CodeGen/TargetRegisterInfo.cpp
llvm/lib/MC/MCRegisterInfo.cpp
llvm/lib/MCA/HardwareUnits/RegisterFile.cpp
llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
llvm/lib/Target/ARM/ARMAsmPrinter.cpp
llvm/lib/Target/ARM/ARMBaseRegisterInfo.cpp
llvm/lib/Target/ARM/Thumb2ITBlockPass.cpp
llvm/lib/Target/BPF/BPFMIChecking.cpp
llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp
llvm/lib/Target/Hexagon/HexagonBlockRanges.cpp
llvm/lib/Target/Hexagon/HexagonCopyToCombine.cpp
llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp
llvm/lib/Target/Hexagon/HexagonGenMux.cpp
llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp
llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCChecker.cpp
llvm/lib/Target/M68k/M68kRegisterInfo.cpp
llvm/lib/Target/SystemZ/SystemZRegisterInfo.cpp
llvm/lib/Target/X86/X86ISelLowering.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/LivePhysRegs.h b/llvm/include/llvm/CodeGen/LivePhysRegs.h
index 27285d63aa834..76bb34d270a26 100644
--- a/llvm/include/llvm/CodeGen/LivePhysRegs.h
+++ b/llvm/include/llvm/CodeGen/LivePhysRegs.h
@@ -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
diff --git a/llvm/include/llvm/MC/MCRegisterInfo.h b/llvm/include/llvm/MC/MCRegisterInfo.h
index 520b6946db91d..d4e236e4af238 100644
--- a/llvm/include/llvm/MC/MCRegisterInfo.h
+++ b/llvm/include/llvm/MC/MCRegisterInfo.h
@@ -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;
}
diff --git a/llvm/lib/CodeGen/AggressiveAntiDepBreaker.cpp b/llvm/lib/CodeGen/AggressiveAntiDepBreaker.cpp
index bb71d72256d81..fb2ddf23c4b15 100644
--- a/llvm/lib/CodeGen/AggressiveAntiDepBreaker.cpp
+++ b/llvm/lib/CodeGen/AggressiveAntiDepBreaker.cpp
@@ -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);
}
}
}
@@ -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;
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
index ab6967f50e306..c9f6c53a7aa51 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
@@ -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"));
@@ -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;
diff --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp
index b5ac90c2e96e3..1b78f5097d073 100644
--- a/llvm/lib/CodeGen/BranchFolding.cpp
+++ b/llvm/lib/CodeGen/BranchFolding.cpp
@@ -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);
diff --git a/llvm/lib/CodeGen/CriticalAntiDepBreaker.cpp b/llvm/lib/CodeGen/CriticalAntiDepBreaker.cpp
index eb2d449bc4af5..6f98e3a5e3de9 100644
--- a/llvm/lib/CodeGen/CriticalAntiDepBreaker.cpp
+++ b/llvm/lib/CodeGen/CriticalAntiDepBreaker.cpp
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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;
@@ -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;
@@ -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) {
diff --git a/llvm/lib/CodeGen/IfConversion.cpp b/llvm/lib/CodeGen/IfConversion.cpp
index 3016a91f49568..deae87aea5409 100644
--- a/llvm/lib/CodeGen/IfConversion.cpp
+++ b/llvm/lib/CodeGen/IfConversion.cpp
@@ -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;
@@ -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);
}
}
}
diff --git a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
index 60a0db596139e..5a65783f5a677 100644
--- a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
+++ b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
@@ -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;
}
}
@@ -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.
@@ -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.
diff --git a/llvm/lib/CodeGen/LiveIntervals.cpp b/llvm/lib/CodeGen/LiveIntervals.cpp
index a49f6b0604c5e..36690ecec08a5 100644
--- a/llvm/lib/CodeGen/LiveIntervals.cpp
+++ b/llvm/lib/CodeGen/LiveIntervals.cpp
@@ -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
@@ -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);
}
diff --git a/llvm/lib/CodeGen/LivePhysRegs.cpp b/llvm/lib/CodeGen/LivePhysRegs.cpp
index d4848f16dcf2d..758dcf8f2e675 100644
--- a/llvm/lib/CodeGen/LivePhysRegs.cpp
+++ b/llvm/lib/CodeGen/LivePhysRegs.cpp
@@ -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;
}
diff --git a/llvm/lib/CodeGen/LiveVariables.cpp b/llvm/lib/CodeGen/LiveVariables.cpp
index 905d268d5ac2c..17c1aa093bdcb 100644
--- a/llvm/lib/CodeGen/LiveVariables.cpp
+++ b/llvm/lib/CodeGen/LiveVariables.cpp
@@ -191,8 +191,7 @@ LiveVariables::FindLastPartialDef(Register Reg,
unsigned LastDefReg = 0;
unsigned LastDefDist = 0;
MachineInstr *LastDef = nullptr;
- for (MCSubRegIterator SubRegs(Reg, TRI); SubRegs.isValid(); ++SubRegs) {
- unsigned SubReg = *SubRegs;
+ for (MCPhysReg SubReg : TRI->subregs(Reg)) {
MachineInstr *Def = PhysRegDef[SubReg];
if (!Def)
continue;
@@ -213,9 +212,8 @@ LiveVariables::FindLastPartialDef(Register Reg,
continue;
Register DefReg = MO.getReg();
if (TRI->isSubRegister(Reg, DefReg)) {
- for (MCSubRegIterator SubRegs(DefReg, TRI, /*IncludeSelf=*/true);
- SubRegs.isValid(); ++SubRegs)
- PartDefRegs.insert(*SubRegs);
+ for (MCPhysReg SubReg : TRI->subregs_inclusive(DefReg))
+ PartDefRegs.insert(SubReg);
}
}
return LastDef;
@@ -244,8 +242,7 @@ void LiveVariables::HandlePhysRegUse(Register Reg, MachineInstr &MI) {
true/*IsImp*/));
PhysRegDef[Reg] = LastPartialDef;
SmallSet<unsigned, 8> Processed;
- for (MCSubRegIterator SubRegs(Reg, TRI); SubRegs.isValid(); ++SubRegs) {
- unsigned SubReg = *SubRegs;
+ for (MCPhysReg SubReg : TRI->subregs(Reg)) {
if (Processed.count(SubReg))
continue;
if (PartDefRegs.count(SubReg))
@@ -256,8 +253,8 @@ void LiveVariables::HandlePhysRegUse(Register Reg, MachineInstr &MI) {
false/*IsDef*/,
true/*IsImp*/));
PhysRegDef[SubReg] = LastPartialDef;
- for (MCSubRegIterator SS(SubReg, TRI); SS.isValid(); ++SS)
- Processed.insert(*SS);
+ for (MCPhysReg SS : TRI->subregs(SubReg))
+ Processed.insert(SS);
}
}
} else if (LastDef && !PhysRegUse[Reg] &&
@@ -267,9 +264,8 @@ void LiveVariables::HandlePhysRegUse(Register Reg, MachineInstr &MI) {
true/*IsImp*/));
// Remember this use.
- for (MCSubRegIterator SubRegs(Reg, TRI, /*IncludeSelf=*/true);
- SubRegs.isValid(); ++SubRegs)
- PhysRegUse[*SubRegs] = &MI;
+ for (MCPhysReg SubReg : TRI->subregs_inclusive(Reg))
+ PhysRegUse[SubReg] = &MI;
}
/// FindLastRefOrPartRef - Return the last reference or partial reference of
@@ -283,8 +279,7 @@ MachineInstr *LiveVariables::FindLastRefOrPartRef(Register Reg) {
MachineInstr *LastRefOrPartRef = LastUse ? LastUse : LastDef;
unsigned LastRefOrPartRefDist = DistanceMap[LastRefOrPartRef];
unsigned LastPartDefDist = 0;
- for (MCSubRegIterator SubRegs(Reg, TRI); SubRegs.isValid(); ++SubRegs) {
- unsigned SubReg = *SubRegs;
+ for (MCPhysReg SubReg : TRI->subregs(Reg)) {
MachineInstr *Def = PhysRegDef[SubReg];
if (Def && Def != LastDef) {
// There was a def of this sub-register in between. This is a partial
@@ -332,8 +327,7 @@ bool LiveVariables::HandlePhysRegKill(Register Reg, MachineInstr *MI) {
MachineInstr *LastPartDef = nullptr;
unsigned LastPartDefDist = 0;
SmallSet<unsigned, 8> PartUses;
- for (MCSubRegIterator SubRegs(Reg, TRI); SubRegs.isValid(); ++SubRegs) {
- unsigned SubReg = *SubRegs;
+ for (MCPhysReg SubReg : TRI->subregs(Reg)) {
MachineInstr *Def = PhysRegDef[SubReg];
if (Def && Def != LastDef) {
// There was a def of this sub-register in between. This is a partial
@@ -346,9 +340,8 @@ bool LiveVariables::HandlePhysRegKill(Register Reg, MachineInstr *MI) {
continue;
}
if (MachineInstr *Use = PhysRegUse[SubReg]) {
- for (MCSubRegIterator SS(SubReg, TRI, /*IncludeSelf=*/true); SS.isValid();
- ++SS)
- PartUses.insert(*SS);
+ for (MCPhysReg SS : TRI->subregs_inclusive(SubReg))
+ PartUses.insert(SS);
unsigned Dist = DistanceMap[Use];
if (Dist > LastRefOrPartRefDist) {
LastRefOrPartRefDist = Dist;
@@ -363,8 +356,7 @@ bool LiveVariables::HandlePhysRegKill(Register Reg, MachineInstr *MI) {
// dead EAX = op implicit-def AL
// That is, EAX def is dead but AL def extends pass it.
PhysRegDef[Reg]->addRegisterDead(Reg, TRI, true);
- for (MCSubRegIterator SubRegs(Reg, TRI); SubRegs.isValid(); ++SubRegs) {
- unsigned SubReg = *SubRegs;
+ for (MCPhysReg SubReg : TRI->subregs(Reg)) {
if (!PartUses.count(SubReg))
continue;
bool NeedDef = true;
@@ -383,12 +375,11 @@ bool LiveVariables::HandlePhysRegKill(Register Reg, MachineInstr *MI) {
LastSubRef->addRegisterKilled(SubReg, TRI, true);
else {
LastRefOrPartRef->addRegisterKilled(SubReg, TRI, true);
- for (MCSubRegIterator SS(SubReg, TRI, /*IncludeSelf=*/true);
- SS.isValid(); ++SS)
- PhysRegUse[*SS] = LastRefOrPartRef;
+ for (MCPhysReg SS : TRI->subregs_inclusive(SubReg))
+ PhysRegUse[SS] = LastRefOrPartRef;
}
- for (MCSubRegIterator SS(SubReg, TRI); SS.isValid(); ++SS)
- PartUses.erase(*SS);
+ for (MCPhysReg SS : TRI->subregs(SubReg))
+ PartUses.erase(SS);
}
} else if (LastRefOrPartRef == PhysRegDef[Reg] && LastRefOrPartRef != MI) {
if (LastPartDef)
@@ -429,9 +420,9 @@ void LiveVariables::HandleRegMask(const MachineOperand &MO) {
// Kill the largest clobbered super-register.
// This avoids needless implicit operands.
unsigned Super = Reg;
- for (MCSuperRegIterator SR(Reg, TRI); SR.isValid(); ++SR)
- if ((PhysRegDef[*SR] || PhysRegUse[*SR]) && MO.clobbersPhysReg(*SR))
- Super = *SR;
+ for (MCPhysReg SR : TRI->superregs(Reg))
+ if ((PhysRegDef[SR] || PhysRegUse[SR]) && MO.clobbersPhysReg(SR))
+ Super = SR;
HandlePhysRegKill(Super, nullptr);
}
}
@@ -441,12 +432,10 @@ void LiveVariables::HandlePhysRegDef(Register Reg, MachineInstr *MI,
// What parts of the register are previously defined?
SmallSet<unsigned, 32> Live;
if (PhysRegDef[Reg] || PhysRegUse[Reg]) {
- for (MCSubRegIterator SubRegs(Reg, TRI, /*IncludeSelf=*/true);
- SubRegs.isValid(); ++SubRegs)
- Live.insert(*SubRegs);
+ for (MCPhysReg SubReg : TRI->subregs_inclusive(Reg))
+ Live.insert(SubReg);
} else {
- for (MCSubRegIterator SubRegs(Reg, TRI); SubRegs.isValid(); ++SubRegs) {
- unsigned SubReg = *SubRegs;
+ for (MCPhysReg SubReg : TRI->subregs(Reg)) {
// If a register isn't itself defined, but all parts that make up of it
// are defined, then consider it also defined.
// e.g.
@@ -456,9 +445,8 @@ void LiveVariables::HandlePhysRegDef(Register Reg, MachineInstr *MI,
if (Live.count(SubReg))
continue;
if (PhysRegDef[SubReg] || PhysRegUse[SubReg]) {
- for (MCSubRegIterator SS(SubReg, TRI, /*IncludeSelf=*/true);
- SS.isValid(); ++SS)
- Live.insert(*SS);
+ for (MCPhysReg SS : TRI->subregs_inclusive(SubReg))
+ Live.insert(SS);
}
}
}
@@ -467,8 +455,7 @@ void LiveVariables::HandlePhysRegDef(Register Reg, MachineInstr *MI,
// is referenced.
HandlePhysRegKill(Reg, MI);
// Only some of the sub-registers are used.
- for (MCSubRegIterator SubRegs(Reg, TRI); SubRegs.isValid(); ++SubRegs) {
- unsigned SubReg = *SubRegs;
+ for (MCPhysReg SubReg : TRI->subregs(Reg)) {
if (!Live.count(SubReg))
// Skip if this sub-register isn't defined.
continue;
@@ -483,9 +470,7 @@ void LiveVariables::UpdatePhysRegDefs(MachineInstr &MI,
SmallVectorImpl<unsigned> &Defs) {
while (!Defs.empty()) {
Register Reg = Defs.pop_back_val();
- for (MCSubRegIterator SubRegs(Reg, TRI, /*IncludeSelf=*/true);
- SubRegs.isValid(); ++SubRegs) {
- unsigned SubReg = *SubRegs;
+ for (MCPhysReg SubReg : TRI->subregs_inclusive(Reg)) {
PhysRegDef[SubReg] = &MI;
PhysRegUse[SubReg] = nullptr;
}
diff --git a/llvm/lib/CodeGen/MachineFrameInfo.cpp b/llvm/lib/CodeGen/MachineFrameInfo.cpp
index daf6a218165d9..280d3a6a41edc 100644
--- a/llvm/lib/CodeGen/MachineFrameInfo.cpp
+++ b/llvm/lib/CodeGen/MachineFrameInfo.cpp
@@ -128,8 +128,8 @@ BitVector MachineFrameInfo::getPristineRegs(const MachineFunction &MF) const {
// Saved CSRs are not pristine.
for (const auto &I : getCalleeSavedInfo())
- for (MCSubRegIterator S(I.getReg(), TRI, true); S.isValid(); ++S)
- BV.reset(*S);
+ for (MCPhysReg S : TRI->subregs_inclusive(I.getReg()))
+ BV.reset(S);
return BV;
}
diff --git a/llvm/lib/CodeGen/MachineInstrBundle.cpp b/llvm/lib/CodeGen/MachineInstrBundle.cpp
index c64e577d463fc..a952a98eda0f7 100644
--- a/llvm/lib/CodeGen/MachineInstrBundle.cpp
+++ b/llvm/lib/CodeGen/MachineInstrBundle.cpp
@@ -197,8 +197,7 @@ void llvm::finalizeBundle(MachineBasicBlock &MBB,
}
if (!MO.isDead() && Reg.isPhysical()) {
- for (MCSubRegIterator SubRegs(Reg, TRI); SubRegs.isValid(); ++SubRegs) {
- unsigned SubReg = *SubRegs;
+ for (MCPhysReg SubReg : TRI->subregs(Reg)) {
if (LocalDefSet.insert(SubReg).second)
LocalDefs.push_back(SubReg);
}
diff --git a/llvm/lib/CodeGen/MachineRegisterInfo.cpp b/llvm/lib/CodeGen/MachineRegisterInfo.cpp
index 377321a165d56..ab41c88253806 100644
--- a/llvm/lib/CodeGen/MachineRegisterInfo.cpp
+++ b/llvm/lib/CodeGen/MachineRegisterInfo.cpp
@@ -645,9 +645,8 @@ bool MachineRegisterInfo::isReservedRegUnit(unsigned Unit) const {
const TargetRegisterInfo *TRI = getTargetRegisterInfo();
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 Super : TRI->superregs_inclusive(*Root)) {
+ MCRegister Reg = Super;
if (!isReserved(Reg)) {
IsRootReserved = false;
break;
diff --git a/llvm/lib/CodeGen/MachineSink.cpp b/llvm/lib/CodeGen/MachineSink.cpp
index 56d27b88678ac..5047503f9011e 100644
--- a/llvm/lib/CodeGen/MachineSink.cpp
+++ b/llvm/lib/CodeGen/MachineSink.cpp
@@ -1700,8 +1700,8 @@ static void updateLiveIn(MachineInstr *MI, MachineBasicBlock *SuccBB,
MachineFunction &MF = *SuccBB->getParent();
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
for (unsigned DefReg : DefedRegsInCopy)
- for (MCSubRegIterator S(DefReg, TRI, true); S.isValid(); ++S)
- SuccBB->removeLiveIn(*S);
+ for (MCPhysReg S : TRI->subregs_inclusive(DefReg))
+ SuccBB->removeLiveIn(S);
for (auto U : UsedOpsInCopy) {
Register SrcReg = MI->getOperand(U).getReg();
LaneBitmask Mask;
diff --git a/llvm/lib/CodeGen/RDFLiveness.cpp b/llvm/lib/CodeGen/RDFLiveness.cpp
index 902b29d41ce17..0cd7364396606 100644
--- a/llvm/lib/CodeGen/RDFLiveness.cpp
+++ b/llvm/lib/CodeGen/RDFLiveness.cpp
@@ -943,8 +943,8 @@ void Liveness::resetKills(MachineBasicBlock *B) {
Register R = Op.getReg();
if (!R.isPhysical())
continue;
- for (MCSubRegIterator SR(R, &TRI, true); SR.isValid(); ++SR)
- Live.reset(*SR);
+ for (MCPhysReg SR : TRI.subregs_inclusive(R))
+ Live.reset(SR);
}
for (auto &Op : MI.operands()) {
if (!Op.isReg() || !Op.isUse() || Op.isUndef())
@@ -961,8 +961,8 @@ void Liveness::resetKills(MachineBasicBlock *B) {
}
if (!IsLive)
Op.setIsKill(true);
- for (MCSubRegIterator SR(R, &TRI, true); SR.isValid(); ++SR)
- Live.set(*SR);
+ for (MCPhysReg SR : TRI.subregs_inclusive(R))
+ Live.set(SR);
}
}
}
diff --git a/llvm/lib/CodeGen/RDFRegisters.cpp b/llvm/lib/CodeGen/RDFRegisters.cpp
index 8760ba118934f..9a1790aac53f5 100644
--- a/llvm/lib/CodeGen/RDFRegisters.cpp
+++ b/llvm/lib/CodeGen/RDFRegisters.cpp
@@ -97,8 +97,8 @@ PhysicalRegisterInfo::PhysicalRegisterInfo(const TargetRegisterInfo &tri,
for (uint32_t U = 0, NU = TRI.getNumRegUnits(); U != NU; ++U) {
BitVector AS(TRI.getNumRegs());
for (MCRegUnitRootIterator R(U, &TRI); R.isValid(); ++R)
- for (MCSuperRegIterator S(*R, &TRI, true); S.isValid(); ++S)
- AS.set(*S);
+ for (MCPhysReg S : TRI.superregs_inclusive(*R))
+ AS.set(S);
AliasInfos[U].Regs = AS;
}
}
diff --git a/llvm/lib/CodeGen/RegUsageInfoCollector.cpp b/llvm/lib/CodeGen/RegUsageInfoCollector.cpp
index 16afd15e29e4c..6657cf3c1ef4a 100644
--- a/llvm/lib/CodeGen/RegUsageInfoCollector.cpp
+++ b/llvm/lib/CodeGen/RegUsageInfoCollector.cpp
@@ -208,8 +208,8 @@ computeCalleeSavedRegs(BitVector &SavedRegs, MachineFunction &MF) {
MCPhysReg Reg = CSRegs[i];
if (SavedRegs.test(Reg)) {
// Save subregisters
- for (MCSubRegIterator SR(Reg, &TRI); SR.isValid(); ++SR)
- SavedRegs.set(*SR);
+ for (MCPhysReg SR : TRI.subregs(Reg))
+ SavedRegs.set(SR);
}
}
}
diff --git a/llvm/lib/CodeGen/RegisterScavenging.cpp b/llvm/lib/CodeGen/RegisterScavenging.cpp
index 8d10a5558315e..b2972a0922193 100644
--- a/llvm/lib/CodeGen/RegisterScavenging.cpp
+++ b/llvm/lib/CodeGen/RegisterScavenging.cpp
@@ -205,8 +205,8 @@ void RegScavenger::forward() {
break;
}
bool SuperUsed = false;
- for (MCSuperRegIterator SR(Reg, TRI); SR.isValid(); ++SR) {
- if (isRegUsed(*SR)) {
+ for (MCPhysReg SR : TRI->superregs(Reg)) {
+ if (isRegUsed(SR)) {
SuperUsed = true;
break;
}
diff --git a/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp b/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp
index 023a5a72eb4e1..57fd31879b383 100644
--- a/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp
+++ b/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp
@@ -334,11 +334,11 @@ void ScheduleDAGInstrs::addPhysRegDeps(SUnit *SU, unsigned OperIdx) {
addPhysRegDataDeps(SU, OperIdx);
// Clear previous uses and defs of this register and its subergisters.
- for (MCSubRegIterator SubReg(Reg, TRI, true); SubReg.isValid(); ++SubReg) {
- if (Uses.contains(*SubReg))
- Uses.eraseAll(*SubReg);
+ for (MCPhysReg SubReg : TRI->subregs_inclusive(Reg)) {
+ if (Uses.contains(SubReg))
+ Uses.eraseAll(SubReg);
if (!MO.isDead())
- Defs.eraseAll(*SubReg);
+ Defs.eraseAll(SubReg);
}
if (MO.isDead() && SU->isCall) {
// Calls will not be reordered because of chain dependencies (see
diff --git a/llvm/lib/CodeGen/StackMaps.cpp b/llvm/lib/CodeGen/StackMaps.cpp
index 8f286c4a17bf4..79b2d42073dd3 100644
--- a/llvm/lib/CodeGen/StackMaps.cpp
+++ b/llvm/lib/CodeGen/StackMaps.cpp
@@ -194,8 +194,11 @@ unsigned StackMaps::getNextMetaArgIdx(const MachineInstr *MI, unsigned CurIdx) {
/// Go up the super-register chain until we hit a valid dwarf register number.
static unsigned getDwarfRegNum(unsigned Reg, const TargetRegisterInfo *TRI) {
int RegNum = TRI->getDwarfRegNum(Reg, false);
- for (MCSuperRegIterator SR(Reg, TRI); SR.isValid() && RegNum < 0; ++SR)
- RegNum = TRI->getDwarfRegNum(*SR, false);
+ for (MCPhysReg SR : TRI->superregs(Reg)) {
+ if (RegNum >= 0)
+ break;
+ RegNum = TRI->getDwarfRegNum(SR, false);
+ }
assert(RegNum >= 0 && "Invalid Dwarf register number.");
return (unsigned)RegNum;
diff --git a/llvm/lib/CodeGen/TargetRegisterInfo.cpp b/llvm/lib/CodeGen/TargetRegisterInfo.cpp
index 051de1612284c..3357be52f2aa7 100644
--- a/llvm/lib/CodeGen/TargetRegisterInfo.cpp
+++ b/llvm/lib/CodeGen/TargetRegisterInfo.cpp
@@ -79,8 +79,8 @@ bool TargetRegisterInfo::shouldRegionSplitForVirtReg(
void TargetRegisterInfo::markSuperRegs(BitVector &RegisterSet,
MCRegister Reg) const {
- for (MCSuperRegIterator AI(Reg, this, true); AI.isValid(); ++AI)
- RegisterSet.set(*AI);
+ for (MCPhysReg SR : superregs_inclusive(Reg))
+ RegisterSet.set(SR);
}
bool TargetRegisterInfo::checkAllSuperRegsMarked(const BitVector &RegisterSet,
@@ -90,9 +90,9 @@ bool TargetRegisterInfo::checkAllSuperRegsMarked(const BitVector &RegisterSet,
for (unsigned Reg : RegisterSet.set_bits()) {
if (Checked[Reg])
continue;
- for (MCSuperRegIterator SR(Reg, this); SR.isValid(); ++SR) {
- if (!RegisterSet[*SR] && !is_contained(Exceptions, Reg)) {
- dbgs() << "Error: Super register " << printReg(*SR, this)
+ for (MCPhysReg SR : superregs(Reg)) {
+ if (!RegisterSet[SR] && !is_contained(Exceptions, Reg)) {
+ dbgs() << "Error: Super register " << printReg(SR, this)
<< " of reserved register " << printReg(Reg, this)
<< " is not reserved.\n";
return false;
@@ -100,7 +100,7 @@ bool TargetRegisterInfo::checkAllSuperRegsMarked(const BitVector &RegisterSet,
// We transitively check superregs. So we can remember this for later
// to avoid compiletime explosion in deep register hierarchies.
- Checked.set(*SR);
+ Checked.set(SR);
}
}
return true;
diff --git a/llvm/lib/MC/MCRegisterInfo.cpp b/llvm/lib/MC/MCRegisterInfo.cpp
index 9f5b08c5cd1cb..f344027d75f2b 100644
--- a/llvm/lib/MC/MCRegisterInfo.cpp
+++ b/llvm/lib/MC/MCRegisterInfo.cpp
@@ -23,9 +23,9 @@ using namespace llvm;
MCRegister
MCRegisterInfo::getMatchingSuperReg(MCRegister Reg, unsigned SubIdx,
const MCRegisterClass *RC) const {
- for (MCSuperRegIterator Supers(Reg, this); Supers.isValid(); ++Supers)
- if (RC->contains(*Supers) && Reg == getSubReg(*Supers, SubIdx))
- return *Supers;
+ for (MCPhysReg Super : superregs(Reg))
+ if (RC->contains(Super) && Reg == getSubReg(Super, SubIdx))
+ return Super;
return 0;
}
@@ -35,9 +35,11 @@ MCRegister MCRegisterInfo::getSubReg(MCRegister Reg, unsigned Idx) const {
// Get a pointer to the corresponding SubRegIndices list. This list has the
// name of each sub-register in the same order as MCSubRegIterator.
const uint16_t *SRI = SubRegIndices + get(Reg).SubRegIndices;
- for (MCSubRegIterator Subs(Reg, this); Subs.isValid(); ++Subs, ++SRI)
+ for (MCPhysReg Sub : subregs(Reg)) {
if (*SRI == Idx)
- return *Subs;
+ return Sub;
+ ++SRI;
+ }
return 0;
}
@@ -47,9 +49,11 @@ unsigned MCRegisterInfo::getSubRegIndex(MCRegister Reg,
// Get a pointer to the corresponding SubRegIndices list. This list has the
// name of each sub-register in the same order as MCSubRegIterator.
const uint16_t *SRI = SubRegIndices + get(Reg).SubRegIndices;
- for (MCSubRegIterator Subs(Reg, this); Subs.isValid(); ++Subs, ++SRI)
- if (*Subs == SubReg)
+ for (MCPhysReg Sub : subregs(Reg)) {
+ if (Sub == SubReg)
return *SRI;
+ ++SRI;
+ }
return 0;
}
diff --git a/llvm/lib/MCA/HardwareUnits/RegisterFile.cpp b/llvm/lib/MCA/HardwareUnits/RegisterFile.cpp
index 474bf84cf8913..53663a10e8a7d 100644
--- a/llvm/lib/MCA/HardwareUnits/RegisterFile.cpp
+++ b/llvm/lib/MCA/HardwareUnits/RegisterFile.cpp
@@ -127,8 +127,8 @@ void RegisterFile::onInstructionExecuted(Instruction *IS) {
if (WR.getWriteState() == &WS)
WR.notifyExecuted(CurrentCycle);
- for (MCSubRegIterator I(RegID, &MRI); I.isValid(); ++I) {
- WriteRef &OtherWR = RegisterMappings[*I].first;
+ for (MCPhysReg I : MRI.subregs(RegID)) {
+ WriteRef &OtherWR = RegisterMappings[I].first;
if (OtherWR.getWriteState() == &WS)
OtherWR.notifyExecuted(CurrentCycle);
}
@@ -136,8 +136,8 @@ void RegisterFile::onInstructionExecuted(Instruction *IS) {
if (!WS.clearsSuperRegisters())
continue;
- for (MCSuperRegIterator I(RegID, &MRI); I.isValid(); ++I) {
- WriteRef &OtherWR = RegisterMappings[*I].first;
+ for (MCPhysReg I : MRI.superregs(RegID)) {
+ WriteRef &OtherWR = RegisterMappings[I].first;
if (OtherWR.getWriteState() == &WS)
OtherWR.notifyExecuted(CurrentCycle);
}
@@ -182,11 +182,11 @@ void RegisterFile::addRegisterFile(const MCRegisterFileDesc &RF,
Entry.AllowMoveElimination = RCE.AllowMoveElimination;
// Assume the same cost for each sub-register.
- for (MCSubRegIterator I(Reg, &MRI); I.isValid(); ++I) {
- RegisterRenamingInfo &OtherEntry = RegisterMappings[*I].second;
+ for (MCPhysReg I : MRI.subregs(Reg)) {
+ RegisterRenamingInfo &OtherEntry = RegisterMappings[I].second;
if (!OtherEntry.IndexPlusCost.first &&
(!OtherEntry.RenameAs ||
- MRI.isSuperRegister(*I, OtherEntry.RenameAs))) {
+ MRI.isSuperRegister(I, OtherEntry.RenameAs))) {
OtherEntry.IndexPlusCost = IPC;
OtherEntry.RenameAs = Reg;
}
@@ -282,8 +282,8 @@ void RegisterFile::addRegisterWrite(WriteRef Write,
MCPhysReg ZeroRegisterID =
WS.clearsSuperRegisters() ? RegID : WS.getRegisterID();
ZeroRegisters.setBitVal(ZeroRegisterID, IsWriteZero);
- for (MCSubRegIterator I(ZeroRegisterID, &MRI); I.isValid(); ++I)
- ZeroRegisters.setBitVal(*I, IsWriteZero);
+ for (MCPhysReg I : MRI.subregs(ZeroRegisterID))
+ ZeroRegisters.setBitVal(I, IsWriteZero);
// If this move has been eliminated, then method tryEliminateMoveOrSwap should
// have already updated all the register mappings.
@@ -304,9 +304,9 @@ void RegisterFile::addRegisterWrite(WriteRef Write,
// Update the mapping for register RegID including its sub-registers.
RegisterMappings[RegID].first = Write;
RegisterMappings[RegID].second.AliasRegID = 0U;
- for (MCSubRegIterator I(RegID, &MRI); I.isValid(); ++I) {
- RegisterMappings[*I].first = Write;
- RegisterMappings[*I].second.AliasRegID = 0U;
+ for (MCPhysReg I : MRI.subregs(RegID)) {
+ RegisterMappings[I].first = Write;
+ RegisterMappings[I].second.AliasRegID = 0U;
}
// No physical registers are allocated for instructions that are optimized
@@ -319,13 +319,13 @@ void RegisterFile::addRegisterWrite(WriteRef Write,
if (!WS.clearsSuperRegisters())
return;
- for (MCSuperRegIterator I(RegID, &MRI); I.isValid(); ++I) {
+ for (MCPhysReg I : MRI.superregs(RegID)) {
if (!IsEliminated) {
- RegisterMappings[*I].first = Write;
- RegisterMappings[*I].second.AliasRegID = 0U;
+ RegisterMappings[I].first = Write;
+ RegisterMappings[I].second.AliasRegID = 0U;
}
- ZeroRegisters.setBitVal(*I, IsWriteZero);
+ ZeroRegisters.setBitVal(I, IsWriteZero);
}
}
@@ -365,8 +365,8 @@ void RegisterFile::removeRegisterWrite(
if (WR.getWriteState() == &WS)
WR.commit();
- for (MCSubRegIterator I(RegID, &MRI); I.isValid(); ++I) {
- WriteRef &OtherWR = RegisterMappings[*I].first;
+ for (MCPhysReg I : MRI.subregs(RegID)) {
+ WriteRef &OtherWR = RegisterMappings[I].first;
if (OtherWR.getWriteState() == &WS)
OtherWR.commit();
}
@@ -374,8 +374,8 @@ void RegisterFile::removeRegisterWrite(
if (!WS.clearsSuperRegisters())
return;
- for (MCSuperRegIterator I(RegID, &MRI); I.isValid(); ++I) {
- WriteRef &OtherWR = RegisterMappings[*I].first;
+ for (MCPhysReg I : MRI.superregs(RegID)) {
+ WriteRef &OtherWR = RegisterMappings[I].first;
if (OtherWR.getWriteState() == &WS)
OtherWR.commit();
}
@@ -472,8 +472,8 @@ bool RegisterFile::tryEliminateMoveOrSwap(MutableArrayRef<WriteState> Writes,
AliasedReg = RMAlias.AliasRegID;
RegisterMappings[AliasReg].second.AliasRegID = AliasedReg;
- for (MCSubRegIterator I(AliasReg, &MRI); I.isValid(); ++I)
- RegisterMappings[*I].second.AliasRegID = AliasedReg;
+ for (MCPhysReg I : MRI.subregs(AliasReg))
+ RegisterMappings[I].second.AliasRegID = AliasedReg;
if (ZeroRegisters[RS.getRegisterID()]) {
WS.setWriteZero();
@@ -530,8 +530,8 @@ void RegisterFile::collectWrites(
}
// Handle potential partial register updates.
- for (MCSubRegIterator I(RegID, &MRI); I.isValid(); ++I) {
- const WriteRef &WR = RegisterMappings[*I].first;
+ for (MCPhysReg I : MRI.subregs(RegID)) {
+ const WriteRef &WR = RegisterMappings[I].first;
if (WR.getWriteState()) {
Writes.push_back(WR);
} else if (WR.hasKnownWriteBackCycle()) {
diff --git a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
index 6f99b2b28c0a0..8a8c14fd057f2 100644
--- a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
@@ -309,12 +309,11 @@ void AArch64RegisterInfo::UpdateCustomCallPreservedMask(MachineFunction &MF,
for (size_t i = 0; i < AArch64::GPR64commonRegClass.getNumRegs(); ++i) {
if (MF.getSubtarget<AArch64Subtarget>().isXRegCustomCalleeSaved(i)) {
- for (MCSubRegIterator SubReg(AArch64::GPR64commonRegClass.getRegister(i),
- this, true);
- SubReg.isValid(); ++SubReg) {
+ for (MCPhysReg SubReg :
+ subregs_inclusive(AArch64::GPR64commonRegClass.getRegister(i))) {
// See TargetRegisterInfo::getCallPreservedMask for how to interpret the
// register mask.
- UpdatedMask[*SubReg / 32] |= 1u << (*SubReg % 32);
+ UpdatedMask[SubReg / 32] |= 1u << (SubReg % 32);
}
}
}
@@ -419,9 +418,8 @@ AArch64RegisterInfo::getStrictlyReservedRegs(const MachineFunction &MF) const {
// SME tiles are not allocatable.
if (MF.getSubtarget<AArch64Subtarget>().hasSME()) {
- for (MCSubRegIterator SubReg(AArch64::ZA, this, /*self=*/true);
- SubReg.isValid(); ++SubReg)
- Reserved.set(*SubReg);
+ for (MCPhysReg SubReg : subregs_inclusive(AArch64::ZA))
+ Reserved.set(SubReg);
}
markSuperRegs(Reserved, AArch64::FPCR);
diff --git a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
index d8c02e5b73921..6bc10429a4e0b 100644
--- a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
+++ b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
@@ -286,11 +286,11 @@ bool ARMAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
// Find the 'd' register that has this 's' register as a sub-register,
// and determine the lane number.
- for (MCSuperRegIterator SR(Reg, TRI); SR.isValid(); ++SR) {
- if (!ARM::DPRRegClass.contains(*SR))
+ for (MCPhysReg SR : TRI->superregs(Reg)) {
+ if (!ARM::DPRRegClass.contains(SR))
continue;
- bool Lane0 = TRI->getSubReg(*SR, ARM::ssub_0) == Reg;
- O << ARMInstPrinter::getRegisterName(*SR) << (Lane0 ? "[0]" : "[1]");
+ bool Lane0 = TRI->getSubReg(SR, ARM::ssub_0) == Reg;
+ O << ARMInstPrinter::getRegisterName(SR) << (Lane0 ? "[0]" : "[1]");
return false;
}
}
diff --git a/llvm/lib/Target/ARM/ARMBaseRegisterInfo.cpp b/llvm/lib/Target/ARM/ARMBaseRegisterInfo.cpp
index 0fc2d8c6f5712..9adf758b46c48 100644
--- a/llvm/lib/Target/ARM/ARMBaseRegisterInfo.cpp
+++ b/llvm/lib/Target/ARM/ARMBaseRegisterInfo.cpp
@@ -222,8 +222,8 @@ getReservedRegs(const MachineFunction &MF) const {
}
const TargetRegisterClass &RC = ARM::GPRPairRegClass;
for (unsigned Reg : RC)
- for (MCSubRegIterator SI(Reg, this); SI.isValid(); ++SI)
- if (Reserved.test(*SI))
+ for (MCPhysReg S : subregs(Reg))
+ if (Reserved.test(S))
markSuperRegs(Reserved, Reg);
// For v8.1m architecture
markSuperRegs(Reserved, ARM::ZR);
@@ -326,9 +326,9 @@ ARMBaseRegisterInfo::getRegPressureLimit(const TargetRegisterClass *RC,
// Get the other register in a GPRPair.
static MCPhysReg getPairedGPR(MCPhysReg Reg, bool Odd,
const MCRegisterInfo *RI) {
- for (MCSuperRegIterator Supers(Reg, RI); Supers.isValid(); ++Supers)
- if (ARM::GPRPairRegClass.contains(*Supers))
- return RI->getSubReg(*Supers, Odd ? ARM::gsub_1 : ARM::gsub_0);
+ for (MCPhysReg Super : RI->superregs(Reg))
+ if (ARM::GPRPairRegClass.contains(Super))
+ return RI->getSubReg(Super, Odd ? ARM::gsub_1 : ARM::gsub_0);
return 0;
}
diff --git a/llvm/lib/Target/ARM/Thumb2ITBlockPass.cpp b/llvm/lib/Target/ARM/Thumb2ITBlockPass.cpp
index 155555152ced1..2945b5eaae3e3 100644
--- a/llvm/lib/Target/ARM/Thumb2ITBlockPass.cpp
+++ b/llvm/lib/Target/ARM/Thumb2ITBlockPass.cpp
@@ -98,9 +98,8 @@ static void TrackDefUses(MachineInstr *MI, RegisterSet &Defs, RegisterSet &Uses,
auto InsertUsesDefs = [&](RegList &Regs, RegisterSet &UsesDefs) {
for (unsigned Reg : Regs)
- for (MCSubRegIterator Subreg(Reg, TRI, /*IncludeSelf=*/true);
- Subreg.isValid(); ++Subreg)
- UsesDefs.insert(*Subreg);
+ for (MCPhysReg Subreg : TRI->subregs_inclusive(Reg))
+ UsesDefs.insert(Subreg);
};
InsertUsesDefs(LocalDefs, Defs);
diff --git a/llvm/lib/Target/BPF/BPFMIChecking.cpp b/llvm/lib/Target/BPF/BPFMIChecking.cpp
index b462f1d1427d0..89ac485b1675e 100644
--- a/llvm/lib/Target/BPF/BPFMIChecking.cpp
+++ b/llvm/lib/Target/BPF/BPFMIChecking.cpp
@@ -145,8 +145,8 @@ static bool hasLiveDefs(const MachineInstr &MI, const TargetRegisterInfo *TRI) {
// Otherwise, return true if any aliased SuperReg of GPR32 is not dead.
for (auto I : GPR32LiveDefs)
- for (MCSuperRegIterator SR(I, TRI); SR.isValid(); ++SR)
- if (!llvm::is_contained(GPR64DeadDefs, *SR))
+ for (MCPhysReg SR : TRI->superregs(I))
+ if (!llvm::is_contained(GPR64DeadDefs, SR))
return true;
return false;
diff --git a/llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp b/llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp
index 688fe6861224a..4ee67cb05d495 100644
--- a/llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp
@@ -66,8 +66,7 @@ void HexagonLowerToMC(const MCInstrInfo &MCII, const MachineInstr *MI,
inline static unsigned getHexagonRegisterPair(unsigned Reg,
const MCRegisterInfo *RI) {
assert(Hexagon::IntRegsRegClass.contains(Reg));
- MCSuperRegIterator SR(Reg, RI, false);
- unsigned Pair = *SR;
+ unsigned Pair = *RI->superregs(Reg).begin();
assert(Hexagon::DoubleRegsRegClass.contains(Pair));
return Pair;
}
diff --git a/llvm/lib/Target/Hexagon/HexagonBlockRanges.cpp b/llvm/lib/Target/Hexagon/HexagonBlockRanges.cpp
index 38103cdd30add..0d3b986b96299 100644
--- a/llvm/lib/Target/Hexagon/HexagonBlockRanges.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonBlockRanges.cpp
@@ -269,11 +269,10 @@ HexagonBlockRanges::RegisterSet HexagonBlockRanges::expandToSubRegs(
}
if (R.Reg.isPhysical()) {
- MCSubRegIterator I(R.Reg, &TRI);
- if (!I.isValid())
+ if (TRI.subregs(R.Reg).empty())
SRs.insert({R.Reg, 0});
- for (; I.isValid(); ++I)
- SRs.insert({*I, 0});
+ for (MCPhysReg I : TRI.subregs(R.Reg))
+ SRs.insert({I, 0});
} else {
assert(R.Reg.isVirtual());
auto &RC = *MRI.getRegClass(R.Reg);
@@ -355,7 +354,7 @@ void HexagonBlockRanges::computeInitialLiveRanges(InstrIndexMap &IndexMap,
// Skip registers that have subregisters. A register is preserved
// iff its bit is set in the regmask, so if R1:0 was preserved, both
// R1 and R0 would also be present.
- if (MCSubRegIterator(PR, &TRI, false).isValid())
+ if (!TRI.subregs(PR).empty())
continue;
if (Reserved[PR])
continue;
@@ -374,8 +373,7 @@ void HexagonBlockRanges::computeInitialLiveRanges(InstrIndexMap &IndexMap,
// Update maps for defs.
for (RegisterRef S : Defs) {
// Defs should already be expanded into subregs.
- assert(!S.Reg.isPhysical() ||
- !MCSubRegIterator(S.Reg, &TRI, false).isValid());
+ assert(!S.Reg.isPhysical() || TRI.subregs(S.Reg).empty());
if (LastDef[S] != IndexType::None || LastUse[S] != IndexType::None)
closeRange(S);
LastDef[S] = Index;
@@ -383,8 +381,7 @@ void HexagonBlockRanges::computeInitialLiveRanges(InstrIndexMap &IndexMap,
// Update maps for clobbers.
for (RegisterRef S : Clobbers) {
// Clobbers should already be expanded into subregs.
- assert(!S.Reg.isPhysical() ||
- !MCSubRegIterator(S.Reg, &TRI, false).isValid());
+ assert(!S.Reg.isPhysical() || TRI.subregs(S.Reg).empty());
if (LastDef[S] != IndexType::None || LastUse[S] != IndexType::None)
closeRange(S);
// Create a single-instruction range.
diff --git a/llvm/lib/Target/Hexagon/HexagonCopyToCombine.cpp b/llvm/lib/Target/Hexagon/HexagonCopyToCombine.cpp
index f630bcba379fc..033e6737f8bb8 100644
--- a/llvm/lib/Target/Hexagon/HexagonCopyToCombine.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonCopyToCombine.cpp
@@ -436,8 +436,8 @@ HexagonCopyToCombine::findPotentialNewifiableTFRs(MachineBasicBlock &BB) {
continue;
Register Reg = Op.getReg();
if (Hexagon::DoubleRegsRegClass.contains(Reg)) {
- for (MCSubRegIterator SubRegs(Reg, TRI); SubRegs.isValid(); ++SubRegs)
- LastDef[*SubRegs] = &MI;
+ for (MCPhysReg SubReg : TRI->subregs(Reg))
+ LastDef[SubReg] = &MI;
} else if (Hexagon::IntRegsRegClass.contains(Reg))
LastDef[Reg] = &MI;
} else if (Op.isRegMask()) {
diff --git a/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp b/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp
index dcb59773ce480..5d5566141a91a 100644
--- a/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp
@@ -252,13 +252,13 @@ static Register getMax32BitSubRegister(Register Reg,
return Reg;
Register RegNo = 0;
- for (MCSubRegIterator SubRegs(Reg, &TRI); SubRegs.isValid(); ++SubRegs) {
+ for (MCPhysReg SubReg : TRI.subregs(Reg)) {
if (hireg) {
- if (*SubRegs > RegNo)
- RegNo = *SubRegs;
+ if (SubReg > RegNo)
+ RegNo = SubReg;
} else {
- if (!RegNo || *SubRegs < RegNo)
- RegNo = *SubRegs;
+ if (!RegNo || SubReg < RegNo)
+ RegNo = SubReg;
}
}
return RegNo;
@@ -311,8 +311,8 @@ static bool needsStackFrame(const MachineBasicBlock &MBB, const BitVector &CSR,
// a stack slot.
if (R.isVirtual())
return true;
- for (MCSubRegIterator S(R, &HRI, true); S.isValid(); ++S)
- if (CSR[*S])
+ for (MCPhysReg S : HRI.subregs_inclusive(R))
+ if (CSR[S])
return true;
continue;
}
@@ -439,8 +439,8 @@ void HexagonFrameLowering::findShrunkPrologEpilog(MachineFunction &MF,
SmallVector<MachineBasicBlock*,16> SFBlocks;
BitVector CSR(Hexagon::NUM_TARGET_REGS);
for (const MCPhysReg *P = HRI.getCalleeSavedRegs(&MF); *P; ++P)
- for (MCSubRegIterator S(*P, &HRI, true); S.isValid(); ++S)
- CSR[*S] = true;
+ for (MCPhysReg S : HRI.subregs_inclusive(*P))
+ CSR[S] = true;
for (auto &I : MF)
if (needsStackFrame(I, CSR, HRI))
@@ -1569,8 +1569,8 @@ bool HexagonFrameLowering::assignCalleeSavedSpillSlots(MachineFunction &MF,
for (const CalleeSavedInfo &I : CSI) {
Register R = I.getReg();
LLVM_DEBUG(dbgs() << ' ' << printReg(R, TRI));
- for (MCSubRegIterator SR(R, TRI, true); SR.isValid(); ++SR)
- SRegs[*SR] = true;
+ for (MCPhysReg SR : TRI->subregs_inclusive(R))
+ SRegs[SR] = true;
}
LLVM_DEBUG(dbgs() << " }\n");
LLVM_DEBUG(dbgs() << "SRegs.1: "; dump_registers(SRegs, *TRI);
@@ -1586,23 +1586,23 @@ bool HexagonFrameLowering::assignCalleeSavedSpillSlots(MachineFunction &MF,
if (AP.isValid()) {
Reserved[AP] = false;
// Unreserve super-regs if no other subregisters are reserved.
- for (MCSuperRegIterator SP(AP, TRI, false); SP.isValid(); ++SP) {
+ for (MCPhysReg SP : TRI->superregs(AP)) {
bool HasResSub = false;
- for (MCSubRegIterator SB(*SP, TRI, false); SB.isValid(); ++SB) {
- if (!Reserved[*SB])
+ for (MCPhysReg SB : TRI->subregs(SP)) {
+ if (!Reserved[SB])
continue;
HasResSub = true;
break;
}
if (!HasResSub)
- Reserved[*SP] = false;
+ Reserved[SP] = false;
}
}
for (int x = Reserved.find_first(); x >= 0; x = Reserved.find_next(x)) {
Register R = x;
- for (MCSuperRegIterator SR(R, TRI, true); SR.isValid(); ++SR)
- SRegs[*SR] = false;
+ for (MCPhysReg SR : TRI->superregs_inclusive(R))
+ SRegs[SR] = false;
}
LLVM_DEBUG(dbgs() << "Res: "; dump_registers(Reserved, *TRI);
dbgs() << "\n");
@@ -1616,13 +1616,13 @@ bool HexagonFrameLowering::assignCalleeSavedSpillSlots(MachineFunction &MF,
BitVector TmpSup(Hexagon::NUM_TARGET_REGS);
for (int x = SRegs.find_first(); x >= 0; x = SRegs.find_next(x)) {
Register R = x;
- for (MCSuperRegIterator SR(R, TRI); SR.isValid(); ++SR)
- TmpSup[*SR] = true;
+ for (MCPhysReg SR : TRI->superregs(R))
+ TmpSup[SR] = true;
}
for (int x = TmpSup.find_first(); x >= 0; x = TmpSup.find_next(x)) {
Register R = x;
- for (MCSubRegIterator SR(R, TRI, true); SR.isValid(); ++SR) {
- if (!Reserved[*SR])
+ for (MCPhysReg SR : TRI->subregs_inclusive(R)) {
+ if (!Reserved[SR])
continue;
TmpSup[R] = false;
break;
@@ -1640,8 +1640,8 @@ bool HexagonFrameLowering::assignCalleeSavedSpillSlots(MachineFunction &MF,
// remove R from SRegs.
for (int x = SRegs.find_first(); x >= 0; x = SRegs.find_next(x)) {
Register R = x;
- for (MCSuperRegIterator SR(R, TRI); SR.isValid(); ++SR) {
- if (!SRegs[*SR])
+ for (MCPhysReg SR : TRI->superregs(R)) {
+ if (!SRegs[SR])
continue;
SRegs[R] = false;
break;
diff --git a/llvm/lib/Target/Hexagon/HexagonGenMux.cpp b/llvm/lib/Target/Hexagon/HexagonGenMux.cpp
index 9461532ab159e..509144ceb6a04 100644
--- a/llvm/lib/Target/Hexagon/HexagonGenMux.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonGenMux.cpp
@@ -144,8 +144,8 @@ INITIALIZE_PASS(HexagonGenMux, "hexagon-gen-mux",
"Hexagon generate mux instructions", false, false)
void HexagonGenMux::getSubRegs(unsigned Reg, BitVector &SRs) const {
- for (MCSubRegIterator I(Reg, HRI); I.isValid(); ++I)
- SRs[*I] = true;
+ for (MCPhysReg I : HRI->subregs(Reg))
+ SRs[I] = true;
}
void HexagonGenMux::expandReg(unsigned Reg, BitVector &Set) const {
@@ -348,9 +348,9 @@ bool HexagonGenMux::genMuxInBlock(MachineBasicBlock &B) {
LivePhysRegs LPR(*HRI);
LPR.addLiveOuts(B);
- auto IsLive = [&LPR,this] (unsigned Reg) -> bool {
- for (MCSubRegIterator S(Reg, HRI, true); S.isValid(); ++S)
- if (LPR.contains(*S))
+ auto IsLive = [&LPR, this](unsigned Reg) -> bool {
+ for (MCPhysReg S : HRI->subregs_inclusive(Reg))
+ if (LPR.contains(S))
return true;
return false;
};
diff --git a/llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp b/llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp
index a2500c188b298..4fd7491ac0a32 100644
--- a/llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp
@@ -2220,13 +2220,13 @@ bool HexagonInstrInfo::isDependent(const MachineInstr &ProdMI,
return true;
if (RegA.isPhysical())
- for (MCSubRegIterator SubRegs(RegA, &HRI); SubRegs.isValid(); ++SubRegs)
- if (RegB == *SubRegs)
+ for (MCPhysReg SubReg : HRI.subregs(RegA))
+ if (RegB == SubReg)
return true;
if (RegB.isPhysical())
- for (MCSubRegIterator SubRegs(RegB, &HRI); SubRegs.isValid(); ++SubRegs)
- if (RegA == *SubRegs)
+ for (MCPhysReg SubReg : HRI.subregs(RegB))
+ if (RegA == SubReg)
return true;
}
@@ -4304,8 +4304,8 @@ int HexagonInstrInfo::getOperandLatency(const InstrItineraryData *ItinData,
if (DefMO.isReg() && DefMO.getReg().isPhysical()) {
if (DefMO.isImplicit()) {
- for (MCSuperRegIterator SR(DefMO.getReg(), &HRI); SR.isValid(); ++SR) {
- int Idx = DefMI.findRegisterDefOperandIdx(*SR, false, false, &HRI);
+ for (MCPhysReg SR : HRI.superregs(DefMO.getReg())) {
+ int Idx = DefMI.findRegisterDefOperandIdx(SR, false, false, &HRI);
if (Idx != -1) {
DefIdx = Idx;
break;
@@ -4315,8 +4315,8 @@ int HexagonInstrInfo::getOperandLatency(const InstrItineraryData *ItinData,
const MachineOperand &UseMO = UseMI.getOperand(UseIdx);
if (UseMO.isImplicit()) {
- for (MCSuperRegIterator SR(UseMO.getReg(), &HRI); SR.isValid(); ++SR) {
- int Idx = UseMI.findRegisterUseOperandIdx(*SR, false, &HRI);
+ for (MCPhysReg SR : HRI.superregs(UseMO.getReg())) {
+ int Idx = UseMI.findRegisterUseOperandIdx(SR, false, &HRI);
if (Idx != -1) {
UseIdx = Idx;
break;
diff --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCChecker.cpp b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCChecker.cpp
index ec84e0ddc259d..ef4c23df54121 100644
--- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCChecker.cpp
+++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCChecker.cpp
@@ -79,9 +79,9 @@ void HexagonMCChecker::initReg(MCInst const &MCI, unsigned R, unsigned &PredReg,
} else
// Note register use. Super-registers are not tracked directly,
// but their components.
- for (MCRegAliasIterator SRI(R, &RI, !MCSubRegIterator(R, &RI).isValid());
- SRI.isValid(); ++SRI)
- if (!MCSubRegIterator(*SRI, &RI).isValid())
+ for (MCRegAliasIterator SRI(R, &RI, RI.subregs(R).empty()); SRI.isValid();
+ ++SRI)
+ if (RI.subregs(*SRI).empty())
// Skip super-registers used indirectly.
Uses.insert(*SRI);
@@ -145,9 +145,9 @@ void HexagonMCChecker::init(MCInst const &MCI) {
// Note register definitions, direct ones as well as indirect side-effects.
// Super-registers are not tracked directly, but their components.
- for (MCRegAliasIterator SRI(R, &RI, !MCSubRegIterator(R, &RI).isValid());
- SRI.isValid(); ++SRI) {
- if (MCSubRegIterator(*SRI, &RI).isValid())
+ for (MCRegAliasIterator SRI(R, &RI, RI.subregs(R).empty()); SRI.isValid();
+ ++SRI) {
+ if (!RI.subregs(*SRI).empty())
// Skip super-registers defined indirectly.
continue;
diff --git a/llvm/lib/Target/M68k/M68kRegisterInfo.cpp b/llvm/lib/Target/M68k/M68kRegisterInfo.cpp
index d12705bc935c7..0ab85cc8ec87e 100644
--- a/llvm/lib/Target/M68k/M68kRegisterInfo.cpp
+++ b/llvm/lib/Target/M68k/M68kRegisterInfo.cpp
@@ -75,7 +75,7 @@ M68kRegisterInfo::getRegsForTailCall(const MachineFunction &MF) const {
unsigned
M68kRegisterInfo::getMatchingMegaReg(unsigned Reg,
const TargetRegisterClass *RC) const {
- for (MCSuperRegIterator Super(Reg, this); Super.isValid(); ++Super)
+ for (MCPhysReg Super : superregs(Reg))
if (RC->contains(*Super))
return *Super;
return 0;
@@ -129,7 +129,7 @@ BitVector M68kRegisterInfo::getReservedRegs(const MachineFunction &MF) const {
for (MCRegAliasIterator I(Reg, this, /* self */ true); I.isValid(); ++I) {
Reserved.set(*I);
}
- for (MCSubRegIterator I(Reg, this, /* self */ true); I.isValid(); ++I) {
+ for (MCPhysReg I : subregs_inclusive(Reg)) {
Reserved.set(*I);
}
};
diff --git a/llvm/lib/Target/SystemZ/SystemZRegisterInfo.cpp b/llvm/lib/Target/SystemZ/SystemZRegisterInfo.cpp
index e43787a5ce710..4d6b94da3a275 100644
--- a/llvm/lib/Target/SystemZ/SystemZRegisterInfo.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZRegisterInfo.cpp
@@ -430,10 +430,9 @@ bool SystemZRegisterInfo::shouldCoalesce(MachineInstr *MI,
for (; MII != MEE; ++MII) {
for (const MachineOperand &MO : MII->operands())
if (MO.isReg() && MO.getReg().isPhysical()) {
- for (MCSuperRegIterator SI(MO.getReg(), this, true/*IncludeSelf*/);
- SI.isValid(); ++SI)
- if (NewRC->contains(*SI)) {
- PhysClobbered.set(*SI);
+ for (MCPhysReg SI : superregs_inclusive(MO.getReg()))
+ if (NewRC->contains(SI)) {
+ PhysClobbered.set(SI);
break;
}
}
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index cacb581c4fd74..e3b47e23e279a 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -3578,9 +3578,8 @@ SDValue X86TargetLowering::LowerCallResult(
// In some calling conventions we need to remove the used registers
// from the register mask.
if (RegMask) {
- for (MCSubRegIterator SubRegs(VA.getLocReg(), TRI, /*IncludeSelf=*/true);
- SubRegs.isValid(); ++SubRegs)
- RegMask[*SubRegs / 32] &= ~(1u << (*SubRegs % 32));
+ for (MCPhysReg SubReg : TRI->subregs_inclusive(VA.getLocReg()))
+ RegMask[SubReg / 32] &= ~(1u << (SubReg % 32));
}
// Report an error if there was an attempt to return FP values via XMM
@@ -4941,9 +4940,8 @@ X86TargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
// in the RegMask.
if (ShouldDisableArgRegs) {
for (auto const &RegPair : RegsToPass)
- for (MCSubRegIterator SubRegs(RegPair.first, TRI, /*IncludeSelf=*/true);
- SubRegs.isValid(); ++SubRegs)
- RegMask[*SubRegs / 32] &= ~(1u << (*SubRegs % 32));
+ for (MCPhysReg SubReg : TRI->subregs_inclusive(RegPair.first))
+ RegMask[SubReg / 32] &= ~(1u << (SubReg % 32));
}
// Create the RegMask Operand according to our updated mask.
More information about the llvm-commits
mailing list