Skip to content

Commit b70b96c

Browse files
committed
[RegAlloc] Simplify RegAllocEvictionAdvisor::canReassign (NFC)
Use range-based for loops. The return type has been changed to bool because the method is only used in boolean contexts. Reviewed By: mtrofin Differential Revision: https://reviews.llvm.org/D152665
1 parent aa2d0fb commit b70b96c

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

llvm/lib/CodeGen/RegAllocEvictionAdvisor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class RegAllocEvictionAdvisor {
121121
protected:
122122
RegAllocEvictionAdvisor(const MachineFunction &MF, const RAGreedy &RA);
123123

124-
Register canReassign(const LiveInterval &VirtReg, Register PrevReg) const;
124+
bool canReassign(const LiveInterval &VirtReg, MCRegister FromReg) const;
125125

126126
// Get the upper limit of elements in the given Order we need to analize.
127127
// TODO: is this heuristic, we could consider learning it.

llvm/lib/CodeGen/RegAllocGreedy.cpp

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -444,31 +444,27 @@ MCRegister RAGreedy::tryAssign(const LiveInterval &VirtReg,
444444
// Interference eviction
445445
//===----------------------------------------------------------------------===//
446446

447-
Register RegAllocEvictionAdvisor::canReassign(const LiveInterval &VirtReg,
448-
Register PrevReg) const {
449-
auto Order =
450-
AllocationOrder::create(VirtReg.reg(), *VRM, RegClassInfo, Matrix);
451-
MCRegister PhysReg;
452-
for (auto I = Order.begin(), E = Order.end(); I != E && !PhysReg; ++I) {
453-
if ((*I).id() == PrevReg.id())
454-
continue;
447+
bool RegAllocEvictionAdvisor::canReassign(const LiveInterval &VirtReg,
448+
MCRegister FromReg) const {
449+
auto HasRegUnitInterference = [&](MCRegUnit Unit) {
450+
// Instantiate a "subquery", not to be confused with the Queries array.
451+
LiveIntervalUnion::Query SubQ(VirtReg, Matrix->getLiveUnions()[Unit]);
452+
return SubQ.checkInterference();
453+
};
455454

456-
MCRegUnitIterator Units(*I, TRI);
457-
for (; Units.isValid(); ++Units) {
458-
// Instantiate a "subquery", not to be confused with the Queries array.
459-
LiveIntervalUnion::Query subQ(VirtReg, Matrix->getLiveUnions()[*Units]);
460-
if (subQ.checkInterference())
461-
break;
455+
for (MCRegister Reg :
456+
AllocationOrder::create(VirtReg.reg(), *VRM, RegClassInfo, Matrix)) {
457+
if (Reg == FromReg)
458+
continue;
459+
// If no units have interference, reassignment is possible.
460+
if (none_of(TRI->regunits(Reg), HasRegUnitInterference)) {
461+
LLVM_DEBUG(dbgs() << "can reassign: " << VirtReg << " from "
462+
<< printReg(FromReg, TRI) << " to "
463+
<< printReg(Reg, TRI) << '\n');
464+
return true;
462465
}
463-
// If no units have interference, break out with the current PhysReg.
464-
if (!Units.isValid())
465-
PhysReg = *I;
466466
}
467-
if (PhysReg)
468-
LLVM_DEBUG(dbgs() << "can reassign: " << VirtReg << " from "
469-
<< printReg(PrevReg, TRI) << " to "
470-
<< printReg(PhysReg, TRI) << '\n');
471-
return PhysReg;
467+
return false;
472468
}
473469

474470
/// evictInterference - Evict any interferring registers that prevent VirtReg

0 commit comments

Comments
 (0)