Skip to content

[CodeGen] Add assertion to MachineBasicBlock::addLiveIn and friends #140527

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions llvm/include/llvm/CodeGen/MachineBasicBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ class MachineBasicBlock
MCRegister PhysReg;
LaneBitmask LaneMask;

RegisterMaskPair(MCPhysReg PhysReg, LaneBitmask LaneMask)
: PhysReg(PhysReg), LaneMask(LaneMask) {}
RegisterMaskPair(MCRegister PhysReg, LaneBitmask LaneMask)
: PhysReg(PhysReg), LaneMask(LaneMask) {
assert(PhysReg.isPhysical());
}

bool operator==(const RegisterMaskPair &other) const {
return PhysReg == other.PhysReg && LaneMask == other.LaneMask;
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/CodeGen/MachineBasicBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ void MachineBasicBlock::printAsOperand(raw_ostream &OS,
}

void MachineBasicBlock::removeLiveIn(MCRegister Reg, LaneBitmask LaneMask) {
assert(Reg.isPhysical());
LiveInVector::iterator I = find_if(
LiveIns, [Reg](const RegisterMaskPair &LI) { return LI.PhysReg == Reg; });
if (I == LiveIns.end())
Expand All @@ -616,6 +617,7 @@ MachineBasicBlock::removeLiveIn(MachineBasicBlock::livein_iterator I) {
}

bool MachineBasicBlock::isLiveIn(MCRegister Reg, LaneBitmask LaneMask) const {
assert(Reg.isPhysical());
livein_iterator I = find_if(
LiveIns, [Reg](const RegisterMaskPair &LI) { return LI.PhysReg == Reg; });
return I != livein_end() && (I->LaneMask & LaneMask).any();
Expand Down Expand Up @@ -1657,6 +1659,7 @@ MachineBasicBlock::LivenessQueryResult
MachineBasicBlock::computeRegisterLiveness(const TargetRegisterInfo *TRI,
MCRegister Reg, const_iterator Before,
unsigned Neighborhood) const {
assert(Reg.isPhysical());
unsigned N = Neighborhood;

// Try searching forwards from Before, looking for reads or defs.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/RegAllocFast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ bool RegAllocFastImpl::mayBeSpillFromInlineAsmBr(const MachineInstr &MI) const {
if (MBB->isInlineAsmBrIndirectTarget() && TII->isStoreToStackSlot(MI, FI) &&
MFI->isSpillSlotObjectIndex(FI))
for (const auto &Op : MI.operands())
if (Op.isReg() && MBB->isLiveIn(Op.getReg()))
if (Op.isReg() && Op.getReg().isValid() && MBB->isLiveIn(Op.getReg()))
return true;
return false;
}
Expand Down