Skip to content

[CodeGen] Use TRI::regunits() (NFC) #137356

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 1 commit into from
Apr 26, 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
4 changes: 2 additions & 2 deletions llvm/include/llvm/CodeGen/RegisterClassInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ class RegisterClassInfo {
/// CalleeSavedAliases.
MCRegister getLastCalleeSavedAlias(MCRegister PhysReg) const {
MCRegister CSR;
for (MCRegUnitIterator UI(PhysReg, TRI); UI.isValid(); ++UI) {
CSR = CalleeSavedAliases[*UI];
for (MCRegUnit Unit : TRI->regunits(PhysReg)) {
CSR = CalleeSavedAliases[Unit];
if (CSR)
break;
}
Expand Down
38 changes: 19 additions & 19 deletions llvm/lib/CodeGen/MachineLICM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,8 @@ static void applyBitsNotInRegMaskToRegUnitsMask(const TargetRegisterInfo &TRI,
break;

if (PhysReg && !((Word >> Bit) & 1)) {
for (MCRegUnitIterator RUI(PhysReg, &TRI); RUI.isValid(); ++RUI)
RUsFromRegsNotInMask.set(*RUI);
for (MCRegUnit Unit : TRI.regunits(PhysReg))
RUsFromRegsNotInMask.set(Unit);
}
}
}
Expand Down Expand Up @@ -542,10 +542,10 @@ void MachineLICMImpl::ProcessMI(MachineInstr *MI, BitVector &RUDefs,

if (!MO.isDef()) {
if (!HasNonInvariantUse) {
for (MCRegUnitIterator RUI(Reg, TRI); RUI.isValid(); ++RUI) {
for (MCRegUnit Unit : TRI->regunits(Reg)) {
// If it's using a non-loop-invariant register, then it's obviously
// not safe to hoist.
if (RUDefs.test(*RUI) || RUClobbers.test(*RUI)) {
if (RUDefs.test(Unit) || RUClobbers.test(Unit)) {
HasNonInvariantUse = true;
break;
}
Expand All @@ -555,8 +555,8 @@ void MachineLICMImpl::ProcessMI(MachineInstr *MI, BitVector &RUDefs,
}

if (MO.isImplicit()) {
for (MCRegUnitIterator RUI(Reg, TRI); RUI.isValid(); ++RUI)
RUClobbers.set(*RUI);
for (MCRegUnit Unit : TRI->regunits(Reg))
RUClobbers.set(Unit);
if (!MO.isDead())
// Non-dead implicit def? This cannot be hoisted.
RuledOut = true;
Expand All @@ -575,17 +575,17 @@ void MachineLICMImpl::ProcessMI(MachineInstr *MI, BitVector &RUDefs,
// If we have already seen another instruction that defines the same
// register, then this is not safe. Two defs is indicated by setting a
// PhysRegClobbers bit.
for (MCRegUnitIterator RUI(Reg, TRI); RUI.isValid(); ++RUI) {
if (RUDefs.test(*RUI)) {
RUClobbers.set(*RUI);
for (MCRegUnit Unit : TRI->regunits(Reg)) {
if (RUDefs.test(Unit)) {
RUClobbers.set(Unit);
RuledOut = true;
} else if (RUClobbers.test(*RUI)) {
} else if (RUClobbers.test(Unit)) {
// MI defined register is seen defined by another instruction in
// the loop, it cannot be a LICM candidate.
RuledOut = true;
}

RUDefs.set(*RUI);
RUDefs.set(Unit);
}
}

Expand Down Expand Up @@ -625,8 +625,8 @@ void MachineLICMImpl::HoistRegionPostRA(MachineLoop *CurLoop) {
// FIXME: That means a reload that're reused in successor block(s) will not
// be LICM'ed.
for (const auto &LI : BB->liveins()) {
for (MCRegUnitIterator RUI(LI.PhysReg, TRI); RUI.isValid(); ++RUI)
RUDefs.set(*RUI);
for (MCRegUnit Unit : TRI->regunits(LI.PhysReg))
RUDefs.set(Unit);
}

// Funclet entry blocks will clobber all registers
Expand All @@ -648,8 +648,8 @@ void MachineLICMImpl::HoistRegionPostRA(MachineLoop *CurLoop) {
Register Reg = MO.getReg();
if (!Reg)
continue;
for (MCRegUnitIterator RUI(Reg, TRI); RUI.isValid(); ++RUI)
TermRUs.set(*RUI);
for (MCRegUnit Unit : TRI->regunits(Reg))
TermRUs.set(Unit);
}
}

Expand All @@ -668,8 +668,8 @@ void MachineLICMImpl::HoistRegionPostRA(MachineLoop *CurLoop) {

Register Def = Candidate.Def;
bool Safe = true;
for (MCRegUnitIterator RUI(Def, TRI); RUI.isValid(); ++RUI) {
if (RUClobbers.test(*RUI) || TermRUs.test(*RUI)) {
for (MCRegUnit Unit : TRI->regunits(Def)) {
if (RUClobbers.test(Unit) || TermRUs.test(Unit)) {
Safe = false;
break;
}
Expand All @@ -682,8 +682,8 @@ void MachineLICMImpl::HoistRegionPostRA(MachineLoop *CurLoop) {
for (const MachineOperand &MO : MI->all_uses()) {
if (!MO.getReg())
continue;
for (MCRegUnitIterator RUI(MO.getReg(), TRI); RUI.isValid(); ++RUI) {
if (RUDefs.test(*RUI) || RUClobbers.test(*RUI)) {
for (MCRegUnit Unit : TRI->regunits(MO.getReg())) {
if (RUDefs.test(Unit) || RUClobbers.test(Unit)) {
// If it's using a non-loop-invariant register, then it's obviously
// not safe to hoist.
Safe = false;
Expand Down
Loading