Move some functionality for adding flags to MachineInstr's into methods on MachineInstr rather than LiveVariables.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46295 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Owen Anderson
2008-01-24 01:10:07 +00:00
parent 3ae054385c
commit b487e7215c
5 changed files with 126 additions and 130 deletions
+90
View File
@@ -623,3 +623,93 @@ void MachineInstr::print(std::ostream &OS, const TargetMachine *TM) const {
OS << "\n";
}
bool MachineInstr::addRegisterKilled(unsigned IncomingReg,
const MRegisterInfo *RegInfo,
bool AddIfNotFound) {
bool Found = false;
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
MachineOperand &MO = getOperand(i);
if (MO.isRegister() && MO.isUse()) {
unsigned Reg = MO.getReg();
if (!Reg)
continue;
if (Reg == IncomingReg) {
MO.setIsKill();
Found = true;
break;
} else if (MRegisterInfo::isPhysicalRegister(Reg) &&
MRegisterInfo::isPhysicalRegister(IncomingReg) &&
RegInfo->isSuperRegister(IncomingReg, Reg) &&
MO.isKill())
// A super-register kill already exists.
Found = true;
}
}
// If not found, this means an alias of one of the operand is killed. Add a
// new implicit operand if required.
if (!Found && AddIfNotFound) {
addOperand(MachineOperand::CreateReg(IncomingReg, false/*IsDef*/,
true/*IsImp*/,true/*IsKill*/));
return true;
}
return Found;
}
bool MachineInstr::addRegisterDead(unsigned IncomingReg,
const MRegisterInfo *RegInfo,
bool AddIfNotFound) {
bool Found = false;
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
MachineOperand &MO = getOperand(i);
if (MO.isRegister() && MO.isDef()) {
unsigned Reg = MO.getReg();
if (!Reg)
continue;
if (Reg == IncomingReg) {
MO.setIsDead();
Found = true;
break;
} else if (MRegisterInfo::isPhysicalRegister(Reg) &&
MRegisterInfo::isPhysicalRegister(IncomingReg) &&
RegInfo->isSuperRegister(IncomingReg, Reg) &&
MO.isDead())
// There exists a super-register that's marked dead.
return true;
}
}
// If not found, this means an alias of one of the operand is dead. Add a
// new implicit operand.
if (!Found && AddIfNotFound) {
addOperand(MachineOperand::CreateReg(IncomingReg, true/*IsDef*/,
true/*IsImp*/,false/*IsKill*/,
true/*IsDead*/));
return true;
}
return Found;
}
/// copyKillDeadInfo - copies killed/dead information from one instr to another
void MachineInstr::copyKillDeadInfo(MachineInstr *OldMI,
const MRegisterInfo *RegInfo) {
// If the instruction defines any virtual registers, update the VarInfo,
// kill and dead information for the instruction.
for (unsigned i = 0, e = OldMI->getNumOperands(); i != e; ++i) {
MachineOperand &MO = OldMI->getOperand(i);
if (MO.isRegister() && MO.getReg() &&
MRegisterInfo::isVirtualRegister(MO.getReg())) {
unsigned Reg = MO.getReg();
if (MO.isDef()) {
if (MO.isDead()) {
MO.setIsDead(false);
addRegisterDead(Reg, RegInfo);
}
}
if (MO.isKill()) {
MO.setIsKill(false);
addRegisterKilled(Reg, RegInfo);
}
}
}
}