[llvm-commits] [llvm] r46295 - in /llvm/trunk: include/llvm/CodeGen/LiveVariables.h include/llvm/CodeGen/MachineInstr.h lib/CodeGen/LiveIntervalAnalysis.cpp lib/CodeGen/LiveVariables.cpp lib/CodeGen/MachineInstr.cpp
Owen Anderson
resistor at mac.com
Wed Jan 23 17:10:08 PST 2008
Author: resistor
Date: Wed Jan 23 19:10:07 2008
New Revision: 46295
URL: http://llvm.org/viewvc/llvm-project?rev=46295&view=rev
Log:
Move some functionality for adding flags to MachineInstr's into methods on MachineInstr rather than LiveVariables.
Modified:
llvm/trunk/include/llvm/CodeGen/LiveVariables.h
llvm/trunk/include/llvm/CodeGen/MachineInstr.h
llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp
llvm/trunk/lib/CodeGen/LiveVariables.cpp
llvm/trunk/lib/CodeGen/MachineInstr.cpp
Modified: llvm/trunk/include/llvm/CodeGen/LiveVariables.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/LiveVariables.h?rev=46295&r1=46294&r2=46295&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/LiveVariables.h (original)
+++ llvm/trunk/include/llvm/CodeGen/LiveVariables.h Wed Jan 23 19:10:07 2008
@@ -196,26 +196,13 @@
/// the records for 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
/// specified register is killed after being used by the specified
/// instruction. If AddIfNotFound is true, add a implicit operand if it's
/// not found.
void addVirtualRegisterKilled(unsigned IncomingReg, MachineInstr *MI,
bool AddIfNotFound = false) {
- if (addRegisterKilled(IncomingReg, MI, RegInfo, AddIfNotFound))
+ if (MI->addRegisterKilled(IncomingReg, RegInfo, AddIfNotFound))
getVarInfo(IncomingReg).Kills.push_back(MI);
}
@@ -246,21 +233,13 @@
/// removeVirtualRegistersKilled - Remove all killed info for the specified
/// instruction.
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
/// register is dead after being used by the specified instruction. If
/// AddIfNotFound is true, add a implicit operand if it's not found.
void addVirtualRegisterDead(unsigned IncomingReg, MachineInstr *MI,
bool AddIfNotFound = false) {
- if (addRegisterDead(IncomingReg, MI, RegInfo, AddIfNotFound))
+ if (MI->addRegisterDead(IncomingReg, RegInfo, AddIfNotFound))
getVarInfo(IncomingReg).Kills.push_back(MI);
}
Modified: llvm/trunk/include/llvm/CodeGen/MachineInstr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineInstr.h?rev=46295&r1=46294&r2=46295&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineInstr.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineInstr.h Wed Jan 23 19:10:07 2008
@@ -21,6 +21,7 @@
namespace llvm {
class TargetInstrDesc;
+class MRegisterInfo;
template <typename T> struct ilist_traits;
template <typename T> struct ilist;
@@ -144,6 +145,24 @@
/// copyPredicates - Copies predicate operand(s) from 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
//
Modified: llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp?rev=46295&r1=46294&r2=46295&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp (original)
+++ llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp Wed Jan 23 19:10:07 2008
@@ -717,7 +717,7 @@
if (lv_)
lv_->instructionChanged(MI, fmi);
else
- LiveVariables::transferKillDeadInfo(MI, fmi, mri_);
+ fmi->copyKillDeadInfo(MI, mri_);
MachineBasicBlock &MBB = *MI->getParent();
if (isSS && !mf_->getFrameInfo()->isImmutableObjectIndex(Slot))
vrm.virtFolded(Reg, MI, fmi, (VirtRegMap::ModRef)MRInfo);
Modified: llvm/trunk/lib/CodeGen/LiveVariables.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveVariables.cpp?rev=46295&r1=46294&r2=46295&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LiveVariables.cpp (original)
+++ llvm/trunk/lib/CodeGen/LiveVariables.cpp Wed Jan 23 19:10:07 2008
@@ -192,73 +192,6 @@
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) {
// Turn previous partial def's into read/mod/write.
for (unsigned i = 0, e = PhysRegPartDef[Reg].size(); i != e; ++i) {
@@ -337,7 +270,7 @@
void LiveVariables::addRegisterKills(unsigned Reg, MachineInstr *MI,
SmallSet<unsigned, 4> &SubKills) {
if (SubKills.count(Reg) == 0)
- addRegisterKilled(Reg, MI, RegInfo, true);
+ MI->addRegisterKilled(Reg, RegInfo, true);
else {
for (const unsigned *SubRegs = RegInfo->getImmediateSubRegisters(Reg);
unsigned SubReg = *SubRegs; ++SubRegs)
@@ -348,7 +281,7 @@
bool LiveVariables::HandlePhysRegKill(unsigned Reg, MachineInstr *RefMI) {
SmallSet<unsigned, 4> SubKills;
if (HandlePhysRegKill(Reg, RefMI, SubKills)) {
- addRegisterKilled(Reg, RefMI, RegInfo, true);
+ RefMI->addRegisterKilled(Reg, RegInfo, true);
return true;
} else {
// Some sub-registers are killed by another MI.
@@ -365,15 +298,15 @@
if (PhysRegUsed[Reg]) {
if (!HandlePhysRegKill(Reg, LastRef)) {
if (PhysRegPartUse[Reg])
- addRegisterKilled(Reg, PhysRegPartUse[Reg], RegInfo, true);
+ PhysRegPartUse[Reg]->addRegisterKilled(Reg, RegInfo, true);
}
} else if (PhysRegPartUse[Reg])
// Add implicit use / kill to last partial use.
- addRegisterKilled(Reg, PhysRegPartUse[Reg], RegInfo, true);
+ PhysRegPartUse[Reg]->addRegisterKilled(Reg, RegInfo, true);
else if (LastRef != MI)
// Defined, but not used. However, watch out for cases where a super-reg
// is also defined on the same MI.
- addRegisterDead(Reg, LastRef, RegInfo);
+ LastRef->addRegisterDead(Reg, RegInfo);
}
for (const unsigned *SubRegs = RegInfo->getSubRegisters(Reg);
@@ -382,14 +315,14 @@
if (PhysRegUsed[SubReg]) {
if (!HandlePhysRegKill(SubReg, LastRef)) {
if (PhysRegPartUse[SubReg])
- addRegisterKilled(SubReg, PhysRegPartUse[SubReg], RegInfo, true);
+ PhysRegPartUse[SubReg]->addRegisterKilled(SubReg, RegInfo, true);
}
} else if (PhysRegPartUse[SubReg])
// 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)
// This must be a def of the subreg on the same MI.
- addRegisterDead(SubReg, LastRef, RegInfo);
+ LastRef->addRegisterDead(SubReg, RegInfo);
}
}
@@ -565,11 +498,13 @@
for (unsigned j = 0, e2 = VirtRegInfo[i].Kills.size(); j != e2; ++j) {
if (VirtRegInfo[i].Kills[j] == MRI.getVRegDef(i +
MRegisterInfo::FirstVirtualRegister))
- addRegisterDead(i + MRegisterInfo::FirstVirtualRegister,
- VirtRegInfo[i].Kills[j], RegInfo);
+ VirtRegInfo[i].Kills[j]->addRegisterDead(i +
+ MRegisterInfo::FirstVirtualRegister,
+ RegInfo);
else
- addRegisterKilled(i + MRegisterInfo::FirstVirtualRegister,
- VirtRegInfo[i].Kills[j], RegInfo);
+ VirtRegInfo[i].Kills[j]->addRegisterKilled(i +
+ MRegisterInfo::FirstVirtualRegister,
+ RegInfo);
}
// Check to make sure there are no unreachable blocks in the MC CFG for the
@@ -620,33 +555,6 @@
}
}
-/// 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
/// instruction.
void LiveVariables::removeVirtualRegistersKilled(MachineInstr *MI) {
Modified: llvm/trunk/lib/CodeGen/MachineInstr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineInstr.cpp?rev=46295&r1=46294&r2=46295&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineInstr.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineInstr.cpp Wed Jan 23 19:10:07 2008
@@ -623,3 +623,93 @@
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);
+ }
+ }
+ }
+}
More information about the llvm-commits
mailing list