Skip to content

Commit

Permalink
[MC] Simplify uses of subregs/superregs. NFC.
Browse files Browse the repository at this point in the history
  • Loading branch information
jayfoad committed Apr 18, 2023
1 parent 54963ca commit c30c5f0
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 57 deletions.
5 changes: 1 addition & 4 deletions llvm/include/llvm/MC/MCRegisterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -657,10 +657,7 @@ 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 (MCPhysReg I : superregs(RegA))
if (I == RegB)
return true;
return false;
return is_contained(superregs(RegA), RegB);
}

//===----------------------------------------------------------------------===//
Expand Down
7 changes: 2 additions & 5 deletions llvm/lib/CodeGen/CriticalAntiDepBreaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,8 @@ void CriticalAntiDepBreaker::ScanInstruction(MachineInstr &MI, unsigned Count) {

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

return true;
return all_of(TRI->subregs_inclusive(PhysReg),
[&](MCPhysReg SR) { return MO.clobbersPhysReg(SR); });
};

for (unsigned i = 0, e = TRI->getNumRegs(); i != e; ++i) {
Expand Down
14 changes: 2 additions & 12 deletions llvm/lib/CodeGen/IfConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1512,19 +1512,9 @@ static void UpdatePredRedefs(MachineInstr &MI, LivePhysRegs &Redefs) {
MIB.addReg(Reg, RegState::Implicit | RegState::Define);
continue;
}
if (LiveBeforeMI.count(Reg))
if (any_of(TRI->subregs_inclusive(Reg),
[&](MCPhysReg S) { return LiveBeforeMI.count(S); }))
MIB.addReg(Reg, RegState::Implicit);
else {
bool HasLiveSubReg = false;
for (MCPhysReg S : TRI->subregs(Reg)) {
if (!LiveBeforeMI.count(S))
continue;
HasLiveSubReg = true;
break;
}
if (HasLiveSubReg)
MIB.addReg(Reg, RegState::Implicit);
}
}
}

Expand Down
11 changes: 3 additions & 8 deletions llvm/lib/CodeGen/LivePhysRegs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,9 @@ void llvm::addLiveIns(MachineBasicBlock &MBB, const LivePhysRegs &LiveRegs) {
if (MRI.isReserved(Reg))
continue;
// Skip the register if we are about to add one of its super registers.
bool ContainsSuperReg = false;
for (MCPhysReg SReg : TRI.superregs(Reg)) {
if (LiveRegs.contains(SReg) && !MRI.isReserved(SReg)) {
ContainsSuperReg = true;
break;
}
}
if (ContainsSuperReg)
if (any_of(TRI.superregs(Reg), [&](MCPhysReg SReg) {
return LiveRegs.contains(SReg) && !MRI.isReserved(SReg);
}))
continue;
MBB.addLiveIn(Reg);
}
Expand Down
11 changes: 2 additions & 9 deletions llvm/lib/CodeGen/MachineRegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,15 +644,8 @@ void MachineRegisterInfo::setCalleeSavedRegs(ArrayRef<MCPhysReg> CSRs) {
bool MachineRegisterInfo::isReservedRegUnit(unsigned Unit) const {
const TargetRegisterInfo *TRI = getTargetRegisterInfo();
for (MCRegUnitRootIterator Root(Unit, TRI); Root.isValid(); ++Root) {
bool IsRootReserved = true;
for (MCPhysReg Super : TRI->superregs_inclusive(*Root)) {
MCRegister Reg = Super;
if (!isReserved(Reg)) {
IsRootReserved = false;
break;
}
}
if (IsRootReserved)
if (all_of(TRI->superregs_inclusive(*Root),
[&](MCPhysReg Super) { return isReserved(Super); }))
return true;
}
return false;
Expand Down
20 changes: 4 additions & 16 deletions llvm/lib/CodeGen/RegisterScavenging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,25 +198,13 @@ void RegScavenger::forward() {
// S1 is can be freely clobbered.
// Ideally we would like a way to model this, but leaving the
// insert_subreg around causes both correctness and performance issues.
bool SubUsed = false;
for (const MCPhysReg &SubReg : TRI->subregs(Reg))
if (isRegUsed(SubReg)) {
SubUsed = true;
break;
}
bool SuperUsed = false;
for (MCPhysReg SR : TRI->superregs(Reg)) {
if (isRegUsed(SR)) {
SuperUsed = true;
break;
}
}
if (!SubUsed && !SuperUsed) {
if (none_of(TRI->subregs(Reg),
[&](MCPhysReg SR) { return isRegUsed(SR); }) &&
none_of(TRI->superregs(Reg),
[&](MCPhysReg SR) { return isRegUsed(SR); })) {
MBB->getParent()->verify(nullptr, "In Register Scavenger");
llvm_unreachable("Using an undefined register!");
}
(void)SubUsed;
(void)SuperUsed;
}
} else {
assert(MO.isDef());
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/CodeGen/StackMaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,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 (MCPhysReg SR : TRI->superregs(Reg)) {
int RegNum;
for (MCPhysReg SR : TRI->superregs_inclusive(Reg)) {
RegNum = TRI->getDwarfRegNum(SR, false);
if (RegNum >= 0)
break;
RegNum = TRI->getDwarfRegNum(SR, false);
}

assert(RegNum >= 0 && "Invalid Dwarf register number.");
Expand Down

0 comments on commit c30c5f0

Please sign in to comment.