Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
31 changes: 31 additions & 0 deletions llvm/include/llvm/CodeGen/Register.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,37 @@ template <> struct DenseMapInfo<Register> {
}
};

/// Wrapper class representing a virtual register or register unit.
class RegisterUnit {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name is still confusing. Maybe VRegOrUnit and VRU for variable names? (Couldn't come up with anything much better.)

unsigned RegUnit;

public:
constexpr explicit RegisterUnit(MCRegUnit Unit) : RegUnit(Unit) {
assert(!Register::isVirtualRegister(RegUnit));
}
constexpr explicit RegisterUnit(Register Reg) : RegUnit(Reg.id()) {
assert(Reg.isVirtual());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(just an idea) Maybe it's worth deleting other constructors to prevent implicit conversions to MCRegUnit / Register?

template<typename T> VirtRegOrUnit(T) = delete;


constexpr bool isVirtual() const {
return Register::isVirtualRegister(RegUnit);
}

constexpr MCRegUnit asMCRegUnit() const {
assert(!isVirtual() && "Not a register unit");
return RegUnit;
}

constexpr Register asVirtualReg() const {
assert(isVirtual() && "Not a virtual register");
return Register(RegUnit);
}

constexpr bool operator==(const RegisterUnit &Other) const {
return RegUnit == Other.RegUnit;
}
};

} // namespace llvm

#endif // LLVM_CODEGEN_REGISTER_H
4 changes: 2 additions & 2 deletions llvm/include/llvm/CodeGen/TargetRegisterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,9 @@ class TargetRegisterInfo : public MCRegisterInfo {
}

/// Returns true if Reg contains RegUnit.
bool hasRegUnit(MCRegister Reg, Register RegUnit) const {
bool hasRegUnit(MCRegister Reg, MCRegUnit RegUnit) const {
for (MCRegUnit Unit : regunits(Reg))
if (Register(Unit) == RegUnit)
if (Unit == RegUnit)
return true;
return false;
}
Expand Down
25 changes: 13 additions & 12 deletions llvm/lib/CodeGen/LiveIntervals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1066,10 +1066,10 @@ class LiveIntervals::HMEditor {
for (LiveInterval::SubRange &S : LI.subranges()) {
if ((S.LaneMask & LaneMask).none())
continue;
updateRange(S, Reg, S.LaneMask);
updateRange(S, RegisterUnit(Reg), S.LaneMask);
}
}
updateRange(LI, Reg, LaneBitmask::getNone());
updateRange(LI, RegisterUnit(Reg), LaneBitmask::getNone());
// If main range has a hole and we are moving a subrange use across
// the hole updateRange() cannot properly handle it since it only
// gets the LiveRange and not the whole LiveInterval. As a result
Expand All @@ -1096,7 +1096,7 @@ class LiveIntervals::HMEditor {
// precomputed live range.
for (MCRegUnit Unit : TRI.regunits(Reg.asMCReg()))
if (LiveRange *LR = getRegUnitLI(Unit))
updateRange(*LR, Unit, LaneBitmask::getNone());
updateRange(*LR, RegisterUnit(Unit), LaneBitmask::getNone());
}
if (hasRegMask)
updateRegMaskSlots();
Expand All @@ -1105,17 +1105,17 @@ class LiveIntervals::HMEditor {
private:
/// Update a single live range, assuming an instruction has been moved from
/// OldIdx to NewIdx.
void updateRange(LiveRange &LR, Register Reg, LaneBitmask LaneMask) {
void updateRange(LiveRange &LR, RegisterUnit Reg, LaneBitmask LaneMask) {
if (!Updated.insert(&LR).second)
return;
LLVM_DEBUG({
dbgs() << " ";
if (Reg.isVirtual()) {
dbgs() << printReg(Reg);
dbgs() << printReg(Reg.asVirtualReg());
if (LaneMask.any())
dbgs() << " L" << PrintLaneMask(LaneMask);
} else {
dbgs() << printRegUnit(Reg, &TRI);
dbgs() << printRegUnit(Reg.asMCRegUnit(), &TRI);
}
dbgs() << ":\t" << LR << '\n';
});
Expand Down Expand Up @@ -1302,7 +1302,7 @@ class LiveIntervals::HMEditor {

/// Update LR to reflect an instruction has been moved upwards from OldIdx
/// to NewIdx (NewIdx < OldIdx).
void handleMoveUp(LiveRange &LR, Register Reg, LaneBitmask LaneMask) {
void handleMoveUp(LiveRange &LR, RegisterUnit RegUnit, LaneBitmask LaneMask) {
LiveRange::iterator E = LR.end();
// Segment going into OldIdx.
LiveRange::iterator OldIdxIn = LR.find(OldIdx.getBaseIndex());
Expand All @@ -1326,7 +1326,7 @@ class LiveIntervals::HMEditor {
SlotIndex DefBeforeOldIdx
= std::max(OldIdxIn->start.getDeadSlot(),
NewIdx.getRegSlot(OldIdxIn->end.isEarlyClobber()));
OldIdxIn->end = findLastUseBefore(DefBeforeOldIdx, Reg, LaneMask);
OldIdxIn->end = findLastUseBefore(DefBeforeOldIdx, RegUnit, LaneMask);

// Did we have a Def at OldIdx? If not we are done now.
OldIdxOut = std::next(OldIdxIn);
Expand Down Expand Up @@ -1484,11 +1484,12 @@ class LiveIntervals::HMEditor {
}

// Return the last use of reg between NewIdx and OldIdx.
SlotIndex findLastUseBefore(SlotIndex Before, Register Reg,
SlotIndex findLastUseBefore(SlotIndex Before, RegisterUnit RegUnit,
LaneBitmask LaneMask) {
if (Reg.isVirtual()) {
if (RegUnit.isVirtual()) {
SlotIndex LastUse = Before;
for (MachineOperand &MO : MRI.use_nodbg_operands(Reg)) {
for (MachineOperand &MO :
MRI.use_nodbg_operands(RegUnit.asVirtualReg())) {
if (MO.isUndef())
continue;
unsigned SubReg = MO.getSubReg();
Expand Down Expand Up @@ -1531,7 +1532,7 @@ class LiveIntervals::HMEditor {
// Check if MII uses Reg.
for (MIBundleOperands MO(*MII); MO.isValid(); ++MO)
if (MO->isReg() && !MO->isUndef() && MO->getReg().isPhysical() &&
TRI.hasRegUnit(MO->getReg(), Reg))
TRI.hasRegUnit(MO->getReg(), RegUnit.asMCRegUnit()))
return Idx.getRegSlot();
}
// Didn't reach Before. It must be the first instruction in the block.
Expand Down
Loading
Loading