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

View File

@@ -196,26 +196,13 @@ public:
/// the records for NewMI. /// the records for NewMI.
void instructionChanged(MachineInstr *OldMI, MachineInstr *NewMI); void instructionChanged(MachineInstr *OldMI, MachineInstr *NewMI);
/// transferKillDeadInfo - Similar to instructionChanged except it does not
/// update live variables internal data structures.
static void transferKillDeadInfo(MachineInstr *OldMI, MachineInstr *NewMI,
const MRegisterInfo *RegInfo);
/// addRegisterKilled - We have determined MI kills a register. Look for the
/// operand that uses it and mark it as IsKill. If AddIfNotFound is true,
/// add a implicit operand if it's not found. Returns true if the operand
/// exists / is added.
static bool addRegisterKilled(unsigned IncomingReg, MachineInstr *MI,
const MRegisterInfo *RegInfo,
bool AddIfNotFound = false);
/// addVirtualRegisterKilled - Add information about the fact that the /// addVirtualRegisterKilled - Add information about the fact that the
/// specified register is killed after being used by the specified /// specified register is killed after being used by the specified
/// instruction. If AddIfNotFound is true, add a implicit operand if it's /// instruction. If AddIfNotFound is true, add a implicit operand if it's
/// not found. /// not found.
void addVirtualRegisterKilled(unsigned IncomingReg, MachineInstr *MI, void addVirtualRegisterKilled(unsigned IncomingReg, MachineInstr *MI,
bool AddIfNotFound = false) { bool AddIfNotFound = false) {
if (addRegisterKilled(IncomingReg, MI, RegInfo, AddIfNotFound)) if (MI->addRegisterKilled(IncomingReg, RegInfo, AddIfNotFound))
getVarInfo(IncomingReg).Kills.push_back(MI); getVarInfo(IncomingReg).Kills.push_back(MI);
} }
@@ -246,21 +233,13 @@ public:
/// removeVirtualRegistersKilled - Remove all killed info for the specified /// removeVirtualRegistersKilled - Remove all killed info for the specified
/// instruction. /// instruction.
void removeVirtualRegistersKilled(MachineInstr *MI); void removeVirtualRegistersKilled(MachineInstr *MI);
/// addRegisterDead - We have determined MI defined a register without a use.
/// Look for the operand that defines it and mark it as IsDead. If
/// AddIfNotFound is true, add a implicit operand if it's not found. Returns
/// true if the operand exists / is added.
static bool addRegisterDead(unsigned IncomingReg, MachineInstr *MI,
const MRegisterInfo *RegInfo,
bool AddIfNotFound = false);
/// addVirtualRegisterDead - Add information about the fact that the specified /// addVirtualRegisterDead - Add information about the fact that the specified
/// register is dead after being used by the specified instruction. If /// register is dead after being used by the specified instruction. If
/// AddIfNotFound is true, add a implicit operand if it's not found. /// AddIfNotFound is true, add a implicit operand if it's not found.
void addVirtualRegisterDead(unsigned IncomingReg, MachineInstr *MI, void addVirtualRegisterDead(unsigned IncomingReg, MachineInstr *MI,
bool AddIfNotFound = false) { bool AddIfNotFound = false) {
if (addRegisterDead(IncomingReg, MI, RegInfo, AddIfNotFound)) if (MI->addRegisterDead(IncomingReg, RegInfo, AddIfNotFound))
getVarInfo(IncomingReg).Kills.push_back(MI); getVarInfo(IncomingReg).Kills.push_back(MI);
} }

View File

@@ -21,6 +21,7 @@
namespace llvm { namespace llvm {
class TargetInstrDesc; class TargetInstrDesc;
class MRegisterInfo;
template <typename T> struct ilist_traits; template <typename T> struct ilist_traits;
template <typename T> struct ilist; template <typename T> struct ilist;
@@ -144,6 +145,24 @@ public:
/// copyPredicates - Copies predicate operand(s) from MI. /// copyPredicates - Copies predicate operand(s) from MI.
void copyPredicates(const MachineInstr *MI); void copyPredicates(const MachineInstr *MI);
/// addRegisterKilled - We have determined MI kills a register. Look for the
/// operand that uses it and mark it as IsKill. If AddIfNotFound is true,
/// add a implicit operand if it's not found. Returns true if the operand
/// exists / is added.
bool addRegisterKilled(unsigned IncomingReg, const MRegisterInfo *RegInfo,
bool AddIfNotFound = false);
/// addRegisterDead - We have determined MI defined a register without a use.
/// Look for the operand that defines it and mark it as IsDead. If
/// AddIfNotFound is true, add a implicit operand if it's not found. Returns
/// true if the operand exists / is added.
bool addRegisterDead(unsigned IncomingReg, const MRegisterInfo *RegInfo,
bool AddIfNotFound = false);
/// copyKillDeadInfo - copies killed/dead information from one instr to another
void copyKillDeadInfo(MachineInstr *OldMI,
const MRegisterInfo *RegInfo);
// //
// Debugging support // Debugging support
// //

View File

@@ -717,7 +717,7 @@ bool LiveIntervals::tryFoldMemoryOperand(MachineInstr* &MI,
if (lv_) if (lv_)
lv_->instructionChanged(MI, fmi); lv_->instructionChanged(MI, fmi);
else else
LiveVariables::transferKillDeadInfo(MI, fmi, mri_); fmi->copyKillDeadInfo(MI, mri_);
MachineBasicBlock &MBB = *MI->getParent(); MachineBasicBlock &MBB = *MI->getParent();
if (isSS && !mf_->getFrameInfo()->isImmutableObjectIndex(Slot)) if (isSS && !mf_->getFrameInfo()->isImmutableObjectIndex(Slot))
vrm.virtFolded(Reg, MI, fmi, (VirtRegMap::ModRef)MRInfo); vrm.virtFolded(Reg, MI, fmi, (VirtRegMap::ModRef)MRInfo);

View File

@@ -192,73 +192,6 @@ void LiveVariables::HandleVirtRegUse(unsigned reg, MachineBasicBlock *MBB,
MarkVirtRegAliveInBlock(VRInfo, MRI.getVRegDef(reg)->getParent(), *PI); MarkVirtRegAliveInBlock(VRInfo, MRI.getVRegDef(reg)->getParent(), *PI);
} }
bool LiveVariables::addRegisterKilled(unsigned IncomingReg, MachineInstr *MI,
const MRegisterInfo *RegInfo,
bool AddIfNotFound) {
bool Found = false;
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
MachineOperand &MO = MI->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) {
MI->addOperand(MachineOperand::CreateReg(IncomingReg, false/*IsDef*/,
true/*IsImp*/,true/*IsKill*/));
return true;
}
return Found;
}
bool LiveVariables::addRegisterDead(unsigned IncomingReg, MachineInstr *MI,
const MRegisterInfo *RegInfo,
bool AddIfNotFound) {
bool Found = false;
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
MachineOperand &MO = MI->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) {
MI->addOperand(MachineOperand::CreateReg(IncomingReg, true/*IsDef*/,
true/*IsImp*/,false/*IsKill*/,
true/*IsDead*/));
return true;
}
return Found;
}
void LiveVariables::HandlePhysRegUse(unsigned Reg, MachineInstr *MI) { void LiveVariables::HandlePhysRegUse(unsigned Reg, MachineInstr *MI) {
// Turn previous partial def's into read/mod/write. // Turn previous partial def's into read/mod/write.
for (unsigned i = 0, e = PhysRegPartDef[Reg].size(); i != e; ++i) { for (unsigned i = 0, e = PhysRegPartDef[Reg].size(); i != e; ++i) {
@@ -337,7 +270,7 @@ bool LiveVariables::HandlePhysRegKill(unsigned Reg, MachineInstr *RefMI,
void LiveVariables::addRegisterKills(unsigned Reg, MachineInstr *MI, void LiveVariables::addRegisterKills(unsigned Reg, MachineInstr *MI,
SmallSet<unsigned, 4> &SubKills) { SmallSet<unsigned, 4> &SubKills) {
if (SubKills.count(Reg) == 0) if (SubKills.count(Reg) == 0)
addRegisterKilled(Reg, MI, RegInfo, true); MI->addRegisterKilled(Reg, RegInfo, true);
else { else {
for (const unsigned *SubRegs = RegInfo->getImmediateSubRegisters(Reg); for (const unsigned *SubRegs = RegInfo->getImmediateSubRegisters(Reg);
unsigned SubReg = *SubRegs; ++SubRegs) unsigned SubReg = *SubRegs; ++SubRegs)
@@ -348,7 +281,7 @@ void LiveVariables::addRegisterKills(unsigned Reg, MachineInstr *MI,
bool LiveVariables::HandlePhysRegKill(unsigned Reg, MachineInstr *RefMI) { bool LiveVariables::HandlePhysRegKill(unsigned Reg, MachineInstr *RefMI) {
SmallSet<unsigned, 4> SubKills; SmallSet<unsigned, 4> SubKills;
if (HandlePhysRegKill(Reg, RefMI, SubKills)) { if (HandlePhysRegKill(Reg, RefMI, SubKills)) {
addRegisterKilled(Reg, RefMI, RegInfo, true); RefMI->addRegisterKilled(Reg, RegInfo, true);
return true; return true;
} else { } else {
// Some sub-registers are killed by another MI. // Some sub-registers are killed by another MI.
@@ -365,15 +298,15 @@ void LiveVariables::HandlePhysRegDef(unsigned Reg, MachineInstr *MI) {
if (PhysRegUsed[Reg]) { if (PhysRegUsed[Reg]) {
if (!HandlePhysRegKill(Reg, LastRef)) { if (!HandlePhysRegKill(Reg, LastRef)) {
if (PhysRegPartUse[Reg]) if (PhysRegPartUse[Reg])
addRegisterKilled(Reg, PhysRegPartUse[Reg], RegInfo, true); PhysRegPartUse[Reg]->addRegisterKilled(Reg, RegInfo, true);
} }
} else if (PhysRegPartUse[Reg]) } else if (PhysRegPartUse[Reg])
// Add implicit use / kill to last partial use. // Add implicit use / kill to last partial use.
addRegisterKilled(Reg, PhysRegPartUse[Reg], RegInfo, true); PhysRegPartUse[Reg]->addRegisterKilled(Reg, RegInfo, true);
else if (LastRef != MI) else if (LastRef != MI)
// Defined, but not used. However, watch out for cases where a super-reg // Defined, but not used. However, watch out for cases where a super-reg
// is also defined on the same MI. // is also defined on the same MI.
addRegisterDead(Reg, LastRef, RegInfo); LastRef->addRegisterDead(Reg, RegInfo);
} }
for (const unsigned *SubRegs = RegInfo->getSubRegisters(Reg); for (const unsigned *SubRegs = RegInfo->getSubRegisters(Reg);
@@ -382,14 +315,14 @@ void LiveVariables::HandlePhysRegDef(unsigned Reg, MachineInstr *MI) {
if (PhysRegUsed[SubReg]) { if (PhysRegUsed[SubReg]) {
if (!HandlePhysRegKill(SubReg, LastRef)) { if (!HandlePhysRegKill(SubReg, LastRef)) {
if (PhysRegPartUse[SubReg]) if (PhysRegPartUse[SubReg])
addRegisterKilled(SubReg, PhysRegPartUse[SubReg], RegInfo, true); PhysRegPartUse[SubReg]->addRegisterKilled(SubReg, RegInfo, true);
} }
} else if (PhysRegPartUse[SubReg]) } else if (PhysRegPartUse[SubReg])
// Add implicit use / kill to last use of a sub-register. // Add implicit use / kill to last use of a sub-register.
addRegisterKilled(SubReg, PhysRegPartUse[SubReg], RegInfo, true); PhysRegPartUse[SubReg]->addRegisterKilled(SubReg, RegInfo, true);
else if (LastRef != MI) else if (LastRef != MI)
// This must be a def of the subreg on the same MI. // This must be a def of the subreg on the same MI.
addRegisterDead(SubReg, LastRef, RegInfo); LastRef->addRegisterDead(SubReg, RegInfo);
} }
} }
@@ -565,11 +498,13 @@ bool LiveVariables::runOnMachineFunction(MachineFunction &mf) {
for (unsigned j = 0, e2 = VirtRegInfo[i].Kills.size(); j != e2; ++j) { for (unsigned j = 0, e2 = VirtRegInfo[i].Kills.size(); j != e2; ++j) {
if (VirtRegInfo[i].Kills[j] == MRI.getVRegDef(i + if (VirtRegInfo[i].Kills[j] == MRI.getVRegDef(i +
MRegisterInfo::FirstVirtualRegister)) MRegisterInfo::FirstVirtualRegister))
addRegisterDead(i + MRegisterInfo::FirstVirtualRegister, VirtRegInfo[i].Kills[j]->addRegisterDead(i +
VirtRegInfo[i].Kills[j], RegInfo); MRegisterInfo::FirstVirtualRegister,
RegInfo);
else else
addRegisterKilled(i + MRegisterInfo::FirstVirtualRegister, VirtRegInfo[i].Kills[j]->addRegisterKilled(i +
VirtRegInfo[i].Kills[j], RegInfo); MRegisterInfo::FirstVirtualRegister,
RegInfo);
} }
// Check to make sure there are no unreachable blocks in the MC CFG for the // Check to make sure there are no unreachable blocks in the MC CFG for the
@@ -620,33 +555,6 @@ void LiveVariables::instructionChanged(MachineInstr *OldMI,
} }
} }
/// transferKillDeadInfo - Similar to instructionChanged except it does not
/// update live variables internal data structures.
void LiveVariables::transferKillDeadInfo(MachineInstr *OldMI,
MachineInstr *NewMI,
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, NewMI, RegInfo);
}
}
if (MO.isKill()) {
MO.setIsKill(false);
addRegisterKilled(Reg, NewMI, RegInfo);
}
}
}
}
/// removeVirtualRegistersKilled - Remove all killed info for the specified /// removeVirtualRegistersKilled - Remove all killed info for the specified
/// instruction. /// instruction.
void LiveVariables::removeVirtualRegistersKilled(MachineInstr *MI) { void LiveVariables::removeVirtualRegistersKilled(MachineInstr *MI) {

View File

@@ -623,3 +623,93 @@ void MachineInstr::print(std::ostream &OS, const TargetMachine *TM) const {
OS << "\n"; 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);
}
}
}
}