Added assertion in getVRegDef of MachineRegisterInfo to make sure the virtual

register does not have multiple definitions. Modified TwoAddressInstructionPass
to use getUniqueVRegDef instead of getVRegDef.

llvm-svn: 159545
This commit is contained in:
Manman Ren 2012-07-02 18:55:36 +00:00
parent 5da53436d5
commit 72098b2c91
2 changed files with 8 additions and 5 deletions

View File

@ -162,6 +162,8 @@ void MachineRegisterInfo::replaceRegWith(unsigned FromReg, unsigned ToReg) {
MachineInstr *MachineRegisterInfo::getVRegDef(unsigned Reg) const { MachineInstr *MachineRegisterInfo::getVRegDef(unsigned Reg) const {
// Since we are in SSA form, we can use the first definition. // Since we are in SSA form, we can use the first definition.
def_iterator I = def_begin(Reg); def_iterator I = def_begin(Reg);
assert((I.atEnd() || llvm::next(I) == def_end()) &&
"getVRegDef assumes a single definition or no definition");
return !I.atEnd() ? &*I : 0; return !I.atEnd() ? &*I : 0;
} }

View File

@ -1536,7 +1536,7 @@ bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &MF) {
// Emit a copy or rematerialize the definition. // Emit a copy or rematerialize the definition.
bool isCopy = false; bool isCopy = false;
const TargetRegisterClass *rc = MRI->getRegClass(regB); const TargetRegisterClass *rc = MRI->getRegClass(regB);
MachineInstr *DefMI = MRI->getVRegDef(regB); MachineInstr *DefMI = MRI->getUniqueVRegDef(regB);
// If it's safe and profitable, remat the definition instead of // If it's safe and profitable, remat the definition instead of
// copying it. // copying it.
if (DefMI && if (DefMI &&
@ -1722,9 +1722,10 @@ TwoAddressInstructionPass::CoalesceExtSubRegs(SmallVector<unsigned,4> &Srcs,
continue; continue;
// Check that the instructions are all in the same basic block. // Check that the instructions are all in the same basic block.
MachineInstr *SrcDefMI = MRI->getVRegDef(SrcReg); MachineInstr *SrcDefMI = MRI->getUniqueVRegDef(SrcReg);
MachineInstr *DstDefMI = MRI->getVRegDef(DstReg); MachineInstr *DstDefMI = MRI->getUniqueVRegDef(DstReg);
if (SrcDefMI->getParent() != DstDefMI->getParent()) if (!SrcDefMI || !DstDefMI ||
SrcDefMI->getParent() != DstDefMI->getParent())
continue; continue;
// If there are no other uses than copies which feed into // If there are no other uses than copies which feed into
@ -1874,7 +1875,7 @@ bool TwoAddressInstructionPass::EliminateRegSequences() {
MachineInstr *DefMI = NULL; MachineInstr *DefMI = NULL;
if (!MI->getOperand(i).getSubReg() && if (!MI->getOperand(i).getSubReg() &&
!TargetRegisterInfo::isPhysicalRegister(SrcReg)) { !TargetRegisterInfo::isPhysicalRegister(SrcReg)) {
DefMI = MRI->getVRegDef(SrcReg); DefMI = MRI->getUniqueVRegDef(SrcReg);
} }
if (DefMI && DefMI->isImplicitDef()) { if (DefMI && DefMI->isImplicitDef()) {